Reputation: 17650
I want to "sync" a remote branch up with head, so that when I finally merge it, it won't be a headache. Thus, I want to try pulling head changes into my branch to see how different it is.
How can I accomplish the following workflow in Git?
Any tips on a better workflow that accomplishes the same thing would be very useful.
Upvotes: 3
Views: 406
Reputation: 497752
This is all pretty basic stuff:
# make sure your notion of the remote is up to date
git fetch origin
# create and check out a branch, at the same place as the remote master branch
git checkout -b origin-master origin/master
# merge your local master
git merge master
# test, edit away, hack hack hack
git add ...
git commit ...
# push back to origin
git push origin origin-master:master
Terminology notes:
Pulling is a combination of fetching and merging. When you're operating with local branches, there's no need to fetch, so you're merging, not pulling.
HEAD doesn't mean what you think it means. (Maybe you're a cvs/svn person.) HEAD is simply the currently checked-out commit (usually referred to via a branch name). So you're not merging HEAD, you're merging that branch. I called it master here.
As for your question about better workflows to do the same thing... well, that's pretty hard to answer. Your goals are a little ambiguous. You said "slowly" sync up and refer to "finally merging it", but the steps you outline do it all at once, so... well, it's all merged. There's nothing to do later. If you wanted to do it incrementally, you could simply repeat the steps I gave, picking intermediate commits in the history to merge each time. It's also a little unclear which direction you want the merging in. Maybe you actually wanted to start from your branch, and merge remote stuff into it?
git checkout -b master-merging master
git fetch origin
git merge origin/master
# test, hack, commit, push...
git push origin master-merging:master
Or with incremental merges:
git checkout -b master-merging master
git fetch origin
git merge origin/master~20 # 20 commits before origin/master
# test, hack, commit
git merge origin/master~10 # 10 commits before origin/master
# test, hack, commit
git merge origin/master
# test, hack, commit, push...
Upvotes: 4