1

Basically, on one PC I created a branch, let's say new_branch and made some changes there. Now I want to get the whole repository from that branch on a different PC.

The problem is that when I'm using:

git checkout new_branch

I get the message that the new_branch does not exist. And by default I'm on master.

How can I do that?

khernik
  • 2,059
  • 2
  • 26
  • 51

1 Answers1

1

Once cloned on the new PC, you can do a:

git checkout -b new_branch origin/new_branch
# or better
git checkout --track origin/new_branch

By default, a clone checks out the master branch, and creates remote tracking branches in the remotes/origin namespace: you you see all those remote tracking branches with git branch -r.

See more with "Difference between git checkout --track origin/branch and git checkout -b branch origin/branch".

If you use the --track option, your local branch will have the remote tracking branch has its upstream branch.
By default, a simple git push would push that local branch on the same branch of the origin repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `git checkout new_branch` if origin/new_branch exists has automatically created the local branch and setup tracking for as far back as my Git memory goes – Andrew C Sep 27 '14 at 16:23
  • @AndrewC indeed. Maybe that clone doesn't have the remote tracking branches, and needs a git fetch to fully list them. – VonC Sep 27 '14 at 16:44