开发者

On a new machine, how do I fetch an existing branch?

开发者 https://www.devze.com 2023-01-27 19:55 出处:网络
I\'m not new to git, but I\'m not a gitmaster. I have an existing branch on my git account, that I would like to pull, but wh开发者_StackOverflowen I do this :

I'm not new to git, but I'm not a gitmaster.

I have an existing branch on my git account, that I would like to pull, but wh开发者_StackOverflowen I do this :

git checkout previously_created_branch

I get..

error: pathspec 'previously_created_branch' did not match any file(s) known to git.

Anyone know how to accomplish this?


Git must know from where you want to get the branch

First fetch the changes from your remote repository:

git fetch origin

Then you can check it out with

git checkout -t origin/previously_created_branch

This will create a local branch of the same name, that tracks the remote branch


git checkout branch-name is used to switch branches.

To pull, you should use: git pull origin branch-name, assuming that your remote is named origin.


Maybe you're not tracking the remote branch on the new machine?

To see the list of remote branches:

git branch -r

To track the branch locally (if it isn't already):

git branch --track previously_created_branch origin/previously_created_branch
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号