简体   繁体   中英

How to add a remote branch to my local repo?

So I haven't found any answers that explains this in a way that I understand. So how do I add a remote branch to my local repo using git?

A simple git fetch should be enough.

Type

cd /path/to/local/repo/on/first/computer
git fetch
git branch -avv

You should see the new branches listed as origin/xxx (namespace ' origin ')

A git switch xxx will create a local branch based on that remote tracking branch origin/xxx .

That will also update your Git repository working tree (ie, your files), which will make them visible in your IDE/editor.

I think others did not understand your question.

You are trying to bring down to your local machine a remote branch that you currently do not have. This could happen if, for instance, your colleague created a new branch.

Now that git switch has been added, this is simple:

git switch <name of remote branch>

Since you do not have the branch locally, this will automatically make switch look on the remote repo. It will then also automatically set up remote branch tracking.

Lastly, this has already been discussed a bunch here on SO. You can look here for more answers, but some are outdated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM