我知道如何创建一个跟踪远程分支的新分支,但是如何使现有分支跟踪远程分支?
我知道我可以编辑.git/config文件,但似乎应该有一个更简单的方法.
我创建了一个本地分支,我想在上游"推".Stack Overflow上有一个关于如何跟踪新创建的远程分支的类似问题.
但是,我的工作流程略有不同.首先,我想创建一个本地分支,当我满意并希望分享我的分支时,我只会将其推送到上游.
更新使用Git 2.0,我在下面写了一个更简单的答案:https://stackoverflow.com/a/27185855/109305
我有两个不同版本的git.在1.6.2版本中,git push没有-u选项.它只出现在1.7.x版本中.
从文档中,-u它与变量有关
branch.<name>.merge
Run Code Online (Sandbox Code Playgroud)
在git config.该变量如下所述:
Defines, together with branch.<name>.remote, the upstream branch
for the given branch. It tells git fetch/git pull which branch to merge.
Run Code Online (Sandbox Code Playgroud)
什么是上游分支?
什么是使用-u标志同时推送到一些git repo的提交?我的意思是什么是git push origin master和git push -u origin master?有人可以描述一下它的用法吗?
可能重复:
"你"究竟做了什么?"git push -u origin master"vs"git push origin master"
在Github中,当您创建一个空存储库时,指令会要求您执行
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,-u选项有什么用?
阅读完联接页后,我仍然没有得到它.
当你创建了一个github-repo并将github-repo添加为远程时
git remote add origin https://github.com/githubname/reponame.git
Run Code Online (Sandbox Code Playgroud)
然后你需要推送你的第一次提交
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
我读过(为什么我需要一直做`--set-upstream`?)这是一个简短的表格
git branch --set-upstream-to my_branch origin/my_branch
git push
Run Code Online (Sandbox Code Playgroud)
什么是上游,我为什么需要设置它?网上几乎没有关于此的信息.我知道有一个类似的话题'git remote add upstream'帮助实现了什么?,但在我看来,它并没有准确解释上游是什么以及什么git push -u origin master做,特别是origin master指出的是,它是本地回购还是远程回购?
有一个名为"my-remote"的远程分支,我以前没有问题.截至今天,我无法推动,我得到不同的错误.
我得到的第一个错误是:
Run Code Online (Sandbox Code Playgroud)hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. If you did not intend to push that branch, you may want to hint: specify branches to push or set the 'push.default' configuration hint: variable to 'current' or 'upstream' to push only the current branch.
我做了一些研究,并希望它可以解决问题:
git config push.default tracking
Run Code Online (Sandbox Code Playgroud)
跑完之后我又跑了一下:
git push https://github.com/someurl/mybranch.git
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
pushing to remote 'https://github.com/someurl/mybranch.git', which is not the upstream of
your current branch 'my-remote', without telling me what …Run Code Online (Sandbox Code Playgroud) 我在 GitLab 上有一个存储库,我也在 GitHub 上发布了它。
到目前为止,我使用的所有 Git 命令都在 GitLab 上进行了更改。但是,我希望在 GitHub 上进行这些提交。
我试过命令:
git remote set-url origin git@github.com:repo-url
Run Code Online (Sandbox Code Playgroud)
有人可以建议我如何设置 URL 以便命令可以在 GitHub 而不是 GitLab 上运行吗?