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?
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.
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.
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.
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 togit 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With