Pull remote branch into local repo with different name?

GitGithubRepository

Git Problem Overview


Alright I did a little bit of research on this but I couldn't find an exact answer, so I have to ask.

I have 2 remotes: origin and repo2.

I'd like to do something like

git pull repo2 master

But this would pull the master branch of the repo2 into my master. Can I specify a different branch to pull into, for my local branch ?

Git Solutions


Solution 1 - Git

git checkout -b myBranchName repo2/master

Solution 2 - Git

The git pull command is a convenience function that does git fetch and git merge. If you only want retrieve branches from a new remote without trying to merge it into any working copy branch you can just use git fetch. You can then refer to git branch -av to see all the local and remote branches and operate on either remote as you like.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCosmin AtanasiuView Question on Stackoverflow
Solution 1 - GitKingCrunchView Answer on Stackoverflow
Solution 2 - GitBen JacksonView Answer on Stackoverflow