0

I created a branch and made a commit a couple days ago. I made some minor changes since that commit so I'm just doing git commit --amend. However, when I push to the remote branch, it fails with tip of your current branch is behind its remote counterpart. I did run git pull prior to initiating the commit. I think I can do a git push --force-with-lease to get it going, but I want to figure out why git push isn't working on its own.

git log $branchname: commit 79c6414 commit db3812b Merge: b50a40d 44768b2 commit b50a40d Merge: 2858711 e581ab6

git log origin/branchname: commit 73a86aa commit db3812b Merge: b50a40d 44768b2 commit b50a40d Merge: 2858711 e581ab6

Brosef
  • 2,945
  • 6
  • 34
  • 69

2 Answers2

0

You have already pushed the previous commits to the remote server. When you amend the local commit, there is one commit missing from your local but existing in the remote. That's why you are behind the remote counterpart. If you want to make the amends available on the remote server, you have to git push <remote> <branch> --force

I think this answer is related.

Community
  • 1
  • 1
thekingofkings
  • 75
  • 1
  • 11
  • Is this the commit thats missing locally 73a86aa? – Brosef Jan 26 '16 at 20:41
  • @Brosef yes, i think it is – thekingofkings Jan 26 '16 at 20:43
  • So that was the very first commit I made to the branch. After some time I made some changes and did `git commit --amend` and ended up with 79c6414. I thought commit --amend is suppose to keep the shame SHA as the previous commit. – Brosef Jan 26 '16 at 20:46
  • @Brosef that's a good question. Actually I am not 100% sure whether --amend will keep the same SHA. But I guess they are different, because the SHA is calculated based on the contents. Your --amend changed the content, thus the SHA should be different. – thekingofkings Jan 26 '16 at 20:49
-1

Do another pull, and push again. This could be due to the unfortunate event of someone committing right before you pushed again.

camel-man
  • 317
  • 1
  • 2
  • 9