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 loca开发者_如何学运维l machine?
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
精彩评论