The branches in consideration are in the published repository server.
Consider a branch A containing a set of commits from which branch B is created. Extra commits are added to the branch B (let's say they are in active development) At this point a commit is added to Branch A.
Now Branch A is behind Branch B by lets say 10 commits and Branch B is behind branch A by a single commit.
Now these two branches cannot be merged as they are both behind each other by atleast a single commit. In order to keep everything in sync, how do I merge branch A and B?
You can merge both branches with git merge
. I don't recommend using git rebase
on this case since you said both branches have already been published to the repository server.
I've created the following situation (described on your post):
$ git co A
$ git lg --all
* 4df39d7 - (HEAD, A) 2nd commit on A (9 seconds ago)
| * f1f57d8 - (B) 1st commit on B (39 seconds ago)
|/
* 8228446 - (master) . (2 minutes ago)
$ git co B
$ git lg --all
* 4df39d7 - (A) 2nd commit on A (2 minutes ago)
| * f1f57d8 - (HEAD, B) 1st commit on B (3 minutes ago)
|/
* 8228446 - (master) . (4 minutes ago)
So assuming we're in branch B
you can merge A
by doing: git merge A
Which turns the history into this:
$ git merge A
$ git lg --all
* 5517453 - (HEAD, B) Merge branch 'A' into B (2 minutes ago)
|\
| * 4df39d7 - (A) 2nd commit on A (5 minutes ago)
* | f1f57d8 - 1st commit on B (6 minutes ago)
|/
* 8228446 - (master) . (7 minutes ago)
Additional note:
The git lg
and git co
are aliases that I've created in order to make it easier to work with the git command line. They stand for (as configured on my .gitconfig
):
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
co = checkout