git - 我如何压制 "fatal: The upstream branch of your current branch does not match the name of your current branch"?

标签 git

SO 上有一个相关问题处理如何更改 push 命令的参数以避免出现此消息:

fatal: The upstream branch of your current branch does not match the name of your current branch

我对如何压制消息本身很感兴趣,无需更改我的本地/远程分支的名称或使用花哨的 push 命令。

假设我有一个本地分支跟踪一个不同名称的远程分支:

user@home:~ git branch -vv
branch-name abcd1234 [remote/origin/branch-name] last commit message

现在我希望能够通过简单地键入 git push 来推送我提交的更改。当我这样做时,我收到以下消息:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:remote/origin/branch-name

To push to the branch of the same name on the remote, use

    git push origin branch-name

即使名称不匹配,如何强制 git 自动推送到上游分支?我正在使用 git 1.9.1

最佳答案

较新的 Git(v 1.9 或更新版本)

git config --global push.default upstream

较旧的 Git

git config --global push.default tracking

Git 2.3 仍然接受 tracking 作为上游的同义词

只需执行一次,每当您“git push”时,它就会将您当前的分支推送到其配置的上游。

这也会在您的全局配置中设置它,它可能会被您的存储库配置中的不同设置 stash 。

关于git - 我如何压制 "fatal: The upstream branch of your current branch does not match the name of your current branch"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25964577/

相关文章:

git - Emacs + GPG + pinentry.el 进行身份验证

ruby - 如何在 docker 容器中使用私有(private) gems(GemFury)?

git - 为什么 .gitattributes 不会覆盖 Linux 上的 core.autocrlf 配置?

git pull --rebase 因冲突而失败,但 git push 有效

svn - git svn dcommit 与 svn 用户名

git - 如何在git中提交多个文件

Git:获取工作树当前状态的哈希值?

Git:为每个 repo 设置不同的本地 user.name 和 user.email

git - 列出计划的 curl 请求中的身份验证失败

r - 运行 git pull 后如何解决错误 bad object refs/heads/main (1)