Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Ahead and Behind together. How to solve? [closed]

I have a commit with 1 ahead and 6 behind.

What should I do in this situation?

I think, that solution might be like this: git push and after git pull

But I think, it can solve only Behind.
Maybe I am wrong.

-------*------*-----*-----*-----B         \          \           \            *-------A 

I make my part and change sdk.
Now I want to merge with B.

like image 404
gaussblurinc Avatar asked Mar 28 '13 09:03

gaussblurinc


People also ask

How can a branch be both ahead and behind?

A branch can be both ahead and behind at the same time if you have made changes to your branch, and someone else have made changes on the default branch that you have not merged into your branch yet.

How do I merge two branches?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.


1 Answers

git pull (or rather, the git merge part that pull does) will "solve" both 'ahead' and 'behind'.

branch is X commits behind means that there are X new (unmerged) commits on the branch which is being tracked by your current branch.

branch is X commits ahead analogously means that your branch has X new commits, which haven't been merged into the tracked branch yet.

Once you've pulled (thereby merging the remote changes into your local ones) and pushed (thereby publishing your changes and the merge to the remote), your own branch and the remote branch will point to the same commit, so neither is ahead or behind.

like image 149
Nevik Rehnel Avatar answered Sep 17 '22 13:09

Nevik Rehnel