Git Switching branch

删除回忆录丶 提交于 2019-12-04 09:24:45

问题


There is somthing I don't get yet with git. It is branch. So let say that I have a local repository A which I clone from a remote one B. So now A have the master branch checked out.

So when I push from A it goes to B master.

B is just a clone on github, a clone of C.

From time to time in other to get in sync I pull from C master branch.

But now C master branch is quite broken for the time being. Since from A I had pull from C my local A is also bugy.

So I would like from A to pull the C stable branch. How do you guys usually do in this situation?

Do you create a new branch on A and pull from C. But since A have the C master change I need to revert it first...


回答1:


git fetch C
git checkout C/stable-branch
git checkout -b myCopy

Then myCopy is a local (copied) branch of C's stable one.




回答2:


In two lines:
git fetch C
git checkout -b myCopy -t C/stable-branch

myCopy is now a local branch of C/stable-branch, and is tracking it, so you can do git push and git pull without a refspec.



来源:https://stackoverflow.com/questions/4826779/git-switching-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!