Reputation: 23
Very new to Git, and I am currently using SourceTree.
I have found myself in a very interesting situation that I cannot seem to get myself out of. I cannot seem to pull, or push code. I seem to be 2 commits ahead, and 2 commits behind,
as illustrated here. I am just trying to get current, so I can pull down all recent code, and continue to work. I am not sure how to proceed.
I don't want to lose the work for my commits, but I would if it really mattered because they are minor.
What is the easiest and most appropriate route to take in order to get the branch up to date and in sync with my local branch?
Upvotes: 1
Views: 17478
Reputation: 336
People probably have made updates into the project you've cloned (that explains the commits behind) and you've also made commits since you've cloned, and didn't pushed yet (and that explains the commits ahead). What you have to do is:
reseting your commits, but keeping the changes by using git reset --soft HEAD^
stash your changes by using git stash
and than,
pull things people updated on your head branch using git pull origin branchName
If you didn't stashed, you will probably get conflicts now, because the system is not smart enough to know whats the priority: what you have changed or what people from other branches changed. That might be not so easy to solve so i strongly recommend you to stash your changes before doing 'pull'.
Now, assuming that you've pulled new things into your branch,
get your updates back on it by doing: git stash apply
Now you have no commits ahead but your changes are waiting to be committed,
so separately, make your commits and than use: git push origin branchName
Upvotes: 2
Reputation: 1044
If you've no uncommitted changes
Just PULL first. SourceTree will ask you to solve merge conflicts if there are any. Then PUSH your changes.
If you've uncommitted changes
Git has a feature called stashing to save your unfinished changes. In SourceTree, do the following steps:
Resolve merge conflicts if there are any. Now you should be able to commit and push like you used to.
Upvotes: 2