0

I just rebased a branch against the master, then committed and pushed the end result.

This seems to work. Git status is showing

nothing to commit, working directory clean

However, when I checked the remote repository, the changed files didn't arrive. This is confusing and a little scary because my local client is saying everything is dandy (all files safely stored remotely), when it really isn't.

Any suggestions on:

  • How to force the push to remote even though local git is thinking there's nothing to push?
  • How to make sure the client correctly indicate the sync status?
Marc
  • 6,773
  • 10
  • 44
  • 68
  • 1
    Turns out this was due to a non fast forward error. The changes were being committed locally but not pushed remotely. – Marc Aug 18 '14 at 04:38

2 Answers2

0

How to make sure the client correctly indicate the sync status?

Before pushing, you can detect if the push will be a fast forward with:

git rev-list origin/yourBranch ^yourBranch

If that returns any commit, it means yourBranch history will be replacing the one from origin, you you would have to force the push to make it happen.
See more at "How to detect a forced update".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

For the first question, the answer is NO, but it should not happen if there's something while the local git thinks there's nothing. Git keeps a remote tracking branch to track the status of remote branches. You can use "git branch -a" to find it.

git branch -a

For push after rebase, you'd better add the option "--force-with-lease". Because it's probably not a fast forward merge after rebase. And "git push" will fail with a non fast forward merge without "--force*" option. With "--force-with-lease", the push only fails if your codes are no longer latest when you do the "rebase". It makes sure that your won't overlay other guys' new commits.

git push origin yourBranch --force-with-lease

For the second question, you may check whether there're commits between your branch and the remote tracking branch with "git log", such as:

git log --graph --pretty=oneline origin/yourBranch..yourBranch 
Landys
  • 7,169
  • 3
  • 25
  • 34