Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

workflow - How do I synchronize two branches in the same Git repository?

Here's a common workflow hurdle I encounter often:

master is our "stable" branch

$ git status
# On branch master
nothing to commit (working directory clean)

Create a module on a branch

$ git checkout -b foo
$ echo "hello" > world
$ git add .
$ git commit -m "init commit for foo module"
$ git checkout master
$ git merge foo

Do work on master or other branches

Over the next couple weeks, more code will be committed to master directly and by other branches. The foo branch will go untouched for this time period.

Resume work/make updates on the foo branch

$ git checkout foo

Oh no! foo is massively out of date! I understand why, but I do need foo back in sync.

The question

How do I get the latest contents from the master branch?

question from:https://stackoverflow.com/questions/4010962/how-do-i-synchronize-two-branches-in-the-same-git-repository

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you don't need the branch around:

If you've merged foo back to master, "git branch -d foo" to kill the topic branch, and then "checkout -b foo" in the future when you need to hack on it again.

If you do need the branch around:

You can rebase your topic branch against the master branch:

git checkout foo
git rebase master

Or:

git rebase master foo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...