10

I have a private project hosted on github. I have a production branch of that project. I got a new machine and I need to fix something on production. This is what I did.

git clone git@github.com:userid/project.git
# now I have master branch
git co -b production
git pull origin production

Using the above mechanism I am able to get production branch but I am getting merge conflicts which I do not want to deal with right now.

Is there a cleaner way of jut getting the production branch code on my local machine?

Roger
  • 3,919
  • 7
  • 30
  • 37
  • 1
    You appear similarly confused as to what was actually happening with all the branches as I remember being when I was new to git. Taking a look at the graphical branching display of `gitk --all` helped me a lot in getting an idea of what is actually going on. – ndim Dec 16 '09 at 23:56

2 Answers2

20

You could checkout directly the remote branch after fetching it

git fetch origin
git branch -f production origin/production
git checkout production

or shorter:

git checkout -b production origin/production

or, with Git 2.23+ (Q3 2019) and git switch:

git switch production

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

git switch -c <branch> --track <remote>/<branch>

You would be directly working from the fetched copy of origin/production branch (no conflict there).

By doing

git co -b production
git pull origin production

You are trying to merge the remote production branch into your master (in a local 'production' branch, which means potentially conflicts if your master has locally a different history than the remote origin/production branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
7

git checkout -b production by itself will checkout a new branch called production based on the branch you currently have checked out, the master.

It's likely that what you actually wanted to do was:

git checkout -b production origin/production
Ben James
  • 121,135
  • 26
  • 193
  • 155