git 无法更新:没有被跟踪的分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24215032/
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
Can't update: no tracked branch
提问by Prince
I am on Android Studio (Preview) 0.6.0 on Windows and was trying to share my project on GitHub. I used Git Shell to initialize, add, commit and push the project to GitHub. But when I tried to update my project from within Android Studio , I got this error:
我在 Windows 上的 Android Studio(预览版)0.6.0 上,并试图在 GitHub 上共享我的项目。我使用 Git Shell 初始化、添加、提交并将项目推送到 GitHub。但是当我尝试从 Android Studio 更新我的项目时,我收到了这个错误:
Can't update: no tracked branch
No tracked branch configured for branch master.
To make your branch track a remote branch call, for example,
git branch --set-upstream master origin/master
It does provide this suggestion but I am not sure what to do at this point. Is there a way to fix this from within Android Studio?
它确实提供了这个建议,但我不确定此时该怎么做。有没有办法从 Android Studio 中解决这个问题?
采纳答案by Prince
So after reading a bit on how git sets up the repo. I realized that I ran the command
所以在阅读了一些关于 git 如何设置 repo 之后。我意识到我运行了命令
git push origin master
but instead for the first time I should have ran
但我应该第一次跑
git push -u origin master
which sets up the upstream initially. Way to go!
最初设置上游。加油!
回答by D. Melo
If I'm not mislead, you just need to set your local branches to track their pairs in the origin server.
如果我没有误导,您只需要设置本地分支以在源服务器中跟踪它们的对。
Using your command line, you can try
使用您的命令行,您可以尝试
git checkout mybranch
git branch --set-upstream-to=origin/mybranch
That will configure something as an equivalent of your local branch in the server. I'll bet that Android Studio is complaining about the lack of that.
这会将某些内容配置为与服务器中的本地分支等效。我敢打赌,Android Studio 正在抱怨缺乏这一点。
If someone knows how to do this using the GUI of that IDE, that would be interesting to read. :)
如果有人知道如何使用该 IDE 的 GUI 来执行此操作,那将会很有趣。:)
回答by raed
I had the same problem when I transferred the ownership of my repository to another user, at first I tried to use git branch --set-upstream-to origin/master master
but the terminal complained so after a little bit of looking around I used the following commandsgit fetch
git branch --set-upstream-to origin/master master
git pull
and everything worked again
当我将我的存储库的所有权转移给另一个用户时,我遇到了同样的问题,起初我尝试使用git branch --set-upstream-to origin/master master
但终端抱怨,所以在稍微环顾四周后,我使用了以下命令git fetch
git branch --set-upstream-to origin/master master
git pull
,一切又正常了
回答by joao.arruda
Create a new folder and run git init
in it.
创建一个新文件夹并git init
在其中运行。
Then try git remote add origin <your-repository-url>
.
然后尝试git remote add origin <your-repository-url>
。
Copy all the files in your project folder to the new folder, except the .git folder (it may be invisible).
将项目文件夹中的所有文件复制到新文件夹中,除了 .git 文件夹(它可能不可见)。
Then you can push your code by doing:git add --all
; or git add -A
; git commit -m "YOUR MESSAGE"
;git push -u origin master
.
然后你就可以做俯卧撑代码:git add --all
; 或git add -A
; git commit -m "YOUR MESSAGE"
; git push -u origin master
.
I think it will work!
我认为它会起作用!
回答by Alexandr Spodin
In the same case this works for me:
在同样的情况下,这对我有用:
< git checkout Branch_name
> Switched to branch 'Branch_name'
< git fetch
> [Branch_name] Branch_name -> origin/Branch_name
< git branch --set-upstream-to origin/Branch_name Branch_name
> Branch Branch_name set up to track remote branch <New_Branch> from origin.
回答by Stan Quinn
git branch --set-upstream-to=origin/master master
Worked for me....where I have a single branch in my repo called master. The response was "Branch master set up to track remote branch master from origin."
对我来说有效......我的仓库中有一个名为 master 的分支。响应是“分支主机设置为从源跟踪远程分支主机。”
回答by Hossam Ali
I have faced The same problem So I used the Git directlyto push the project to GitHub.
我遇到了同样的问题所以我直接使用Git将项目推送到GitHub。
In your android studio
在你的安卓工作室
Go to VCS=>Git=> Push: use the Branch Name You Commit and hit Push Button
转到 VCS=>Git=> Push:使用您提交的分支名称并点击Push Button
Note: tested for android studio version 3.3
注意:已针对 android studio 3.3 版进行测试
回答by Nic Scozzaro
I got the same error but in PyCharm because I accidentally deleted my VCS origin. After re-adding my origin I ran:
我在 PyCharm 中遇到了同样的错误,因为我不小心删除了我的 VCS 源。重新添加我的原点后,我跑了:
git fetch
which reloaded all of my branches. I then clicked the button to update the project, and I was back to normal.
这重新加载了我所有的分支。然后我点击按钮更新项目,我就恢复正常了。
回答by CoolMind
Assume you have a local branch "Branch-200" (or other name) and server repository contains "origin/Branch-1". If you have local "Branch-1" not linked with "origin/Branch-1", rename it to "Branch-200".
假设您有一个本地分支“Branch-200”(或其他名称)并且服务器存储库包含“origin/Branch-1”。如果您有未与“origin/Branch-1”链接的本地“Branch-1”,请将其重命名为“Branch-200”。
In Android Studio checkout to "origin/Branch-1" creating a new local branch "Branch-1", then merge with you local branch "Branch-200".
在 Android Studio 结帐到“origin/Branch-1”创建一个新的本地分支“Branch-1”,然后与您本地分支“Branch-200”合并。
回答by Saeed Zahedian Abroodi
This isuse because of coflict merge. If you have new commit in origin and not get those files; also you have changed the local master branch files then you got this error. You should fetch again to a new directory and copy your files into that path. Finally, you should commit and push your changes.
这是因为冲突合并。如果您有新的原始提交并且没有获得这些文件;您也更改了本地主分支文件,然后出现此错误。您应该再次获取到一个新目录并将您的文件复制到该路径中。最后,您应该提交并推送您的更改。