Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github how to checkout production branch

Tags:

git

github

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 [email protected]: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?

like image 934
Roger Avatar asked Dec 13 '09 19:12

Roger


People also ask

How do I checkout a specific branch in GitHub?

Using the “-b” option, you are fetching all the branches but you are checking out the branch you chose. It means that if you run “git branch” with the “-a” (for all) option, you are going to see that all your branches were fetched. Note : you have to execute this command into the Git repository you just cloned.

How do I checkout to a new branch?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How do I checkout from GitHub?

This is accomplished by entering the command 'git branch' in the command line. After entering the command you will be presented with a list of all available branches in your repository. These are the branches that you can switch to using the checkout command.


2 Answers

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.

like image 157
VonC Avatar answered Sep 21 '22 18:09

VonC


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
like image 31
Ben James Avatar answered Sep 22 '22 18:09

Ben James