git 当前分支没有跟踪信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32056324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
There is no tracking information for the current branch
提问by valerio0999
I've been using github from a relatively short period, and I've always used the client to perform commits and pulls. I decided to try it from the git bash yesterday, and I successfully created a new repo and committed files.
我从相对较短的时间开始使用 github,并且我一直使用客户端来执行提交和拉取。我昨天决定从 git bash 中尝试一下,我成功地创建了一个新的 repo 并提交了文件。
Today I did changes to the repository from another computer, I've committed the changes and now I'm back home and performed a git pull
to update my local version and I get this:
今天我从另一台计算机对存储库进行了更改,我已经提交了更改,现在我回到家并执行了git pull
更新我的本地版本,我得到了这个:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream develop origin/<branch>
the only contributor to this repo is me and there are no branches (just a master). I'm on windows and I've performed the pull from git bash:
这个 repo 的唯一贡献者是我,没有分支(只有一个 master)。我在 Windows 上,我已经从 git bash 执行了拉取:
git status:
git状态:
$ git status
# On branch master
nothing to commit, working directory clean
git branch:
git分支:
$ git branch
* master
What am I doing wrong?
我究竟做错了什么?
回答by ComputerDruid
You could specify what branch you want to pull:
您可以指定要拉取的分支:
git pull origin master
Or you could set it up so that your local master branch tracks github master branch as an upstream:
或者您可以设置它,以便您的本地 master 分支将 github master 分支作为上游跟踪:
git branch --set-upstream-to=origin/master master
git pull
This branch tracking is set up for you automatically when you clone a repository (for the default branch only), but if you add a remote to an existing repository you have to set up the tracking yourself. Thankfully, the advice given by git makes that pretty easy to remember how to do.
当您克隆存储库(仅适用于默认分支)时,会自动为您设置此分支跟踪,但是如果您将远程添加到现有存储库,则必须自己设置跟踪。值得庆幸的是,git 给出的建议让你很容易记住该怎么做。
回答by rjmunro
See: git checkout tag, git pull fails in branch
请参阅:git checkout 标签,git pull 在分支中失败
If like me you need to do this all the time, you can set up an alias to do it automatically by adding the following to your .gitconfig
file:
如果像我一样您需要一直这样做,您可以通过将以下内容添加到您的.gitconfig
文件中来设置别名以自动执行此操作:
[alias]
set-upstream = \
!git branch \
--set-upstream-to=origin/`git symbolic-ref --short HEAD`
When you see the message There is no tracking information...
, run:
当您看到消息时There is no tracking information...
,请运行:
git set-upstream
git push
回答by Aerin
ComputerDruid's answer is great but I don't think it's necessary to set upstream manually unless you want to. I'm adding this answer because people might think that that's a necessary step.
ComputerDruid 的回答很好,但我认为除非您愿意,否则没有必要手动设置上游。我添加这个答案是因为人们可能认为这是必要的步骤。
This error will be gone if you specify the remote that you want to pull like below:
如果您指定要拉的遥控器,则此错误将消失,如下所示:
git pull origin master
Note that origin
is the name of the remote and master
is the branch name.
请注意,这origin
是远程的名称,master
是分支名称。
1) How to check remote's name
1) 如何查看遥控器名称
git remote -v
2) How to see what branches available in the repository.
2)如何查看存储库中可用的分支。
git branch -r
回答by Ron Reynolds
I run into this exact message often because I create a local branches via git checkout -b <feature-branch-name>
without first creating the remote branch.
我经常遇到这个确切的消息,因为我在git checkout -b <feature-branch-name>
没有首先创建远程分支的情况下创建了一个本地分支。
After all the work was finished and committed locally the fix was git push -u
which created the remote branch, pushed all my work, and then the merge-request URL.
在所有工作完成并在本地提交后,修复程序是git push -u
创建远程分支,推送我所有的工作,然后是合并请求 URL。
回答by imapotatoe123
I was trying the above examples and couldn't get them to sync with a (non-master) branch I had created on a different computer. For background, I created this repository on computer A (git v 1.8) and then cloned the repository onto computer B (git 2.14). I made all my changes on comp B, but when I tried to pull the changes onto computer A I was unable to do so, getting the same above error. Similar to the above solutions, I had to do:
我正在尝试上述示例,但无法让它们与我在另一台计算机上创建的(非主)分支同步。作为背景,我在计算机 A (git v 1.8) 上创建了这个存储库,然后将存储库克隆到计算机 B (git 2.14) 上。我在 comp B 上进行了所有更改,但是当我尝试将更改拉到计算机 AI 上时却无法这样做,出现上述相同的错误。与上述解决方案类似,我必须这样做:
git branch --set-upstream-to=origin/<my_repository_name>
git pull
slightly different but hopefully helps someone
略有不同,但希望对某人有所帮助
回答by maheshmnj
try
尝试
git pull --rebase
hope this answer helps originally answered here https://stackoverflow.com/a/55015370/8253662
希望这个答案有助于最初在这里回答https://stackoverflow.com/a/55015370/8253662
回答by VonC
With Git 2.24, you won't have to do
使用 Git 2.24,您将不必做
git branch --set-upstream-to=origin/master master
git pull
You will be able to do:
您将能够:
git pull --set-upstream-to=origin/master master
See more at "default remote and branch using -u
option - works with push
but not pull
".
在“使用-u
选项的默认远程和分支- 使用push
但不使用pull
”中查看更多信息。
回答by MERLIN THOMAS
1) git branch --set-upstream-to=origin/<master_branch>
feature/<your_current_branch>
1) git branch --set-upstream-to=origin/ <master_branch>
feature/<your_current_branch>
2) git pull
2)git拉
回答by May Dias
$ git branch --set-upstream-to=heroku/master master
and
$ git branch --set-upstream-to=heroku/master master
和
$ git pull
worked for me!
对我来说有效!
回答by Newt
The same thing happened to me before when I created a new git branch while not pushing it to origin.
同样的事情发生在我之前,当我创建一个新的 git 分支而不将它推送到原点时。
Try to execute those two lines first:
尝试先执行这两行:
git checkout -b name_of_new_branch # create the new branch
git push origin name_of_new_branch # push the branch to github
Then:
然后:
git pull origin name_of_new_branch
It should be fine now!
现在应该没问题了!