1

Im using a private github repo for a project on which I'm the sole developer.

Yesterday, after pushing my latest changes to github, I decided to try my hand at rebasing some of my local commits to clean things up a bit. I followed Github's rebase tutorial and did not heed the warning at the top:

Warning: It is considered bad practice to rebase commits which you have already pushed to a remote repository. Doing so may invoke the wrath of the git gods.

After squashing some commits, I tried a push, and got this:

$ git push origin master
To git@github.com:me/my-repo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:me/my-repo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Ok, it wants me to merge remote changes, but I haven't made any so I'll ignore that. Looking at the help section, it looks like I have the option to force a push with:

git push --force

Considering no one else has touched the remote repo and there's been no changes between my last push and the rebasing, is this ok to do, or will there still be consequences?

Yarin
  • 173,523
  • 149
  • 402
  • 512
  • Since it's a private repo and you're the only one using it, it's probably fine to force push. Just don't make it a habit. :-) – peterjmag Sep 30 '13 at 14:11

2 Answers2

3

You will need to force push. What you are doing is much the same as 'git reset' backwards to some previous commit, then redoing your work with fewer 'cleaner' commits. As long as you are the only user, go for it. Remember that ANY local copies you have of the remote hanging around in a directory somewhere will now be in conflict with your remote. You will want to clone before working again. One other warning is that if you realize there was code in one of those commits you blasted away with a force push, you're not getting it back.

Andrew
  • 906
  • 7
  • 9
2

Since you are the only contributor, yes it's fine.

Problems would arise if anyone else had pulled the repo in the meantime, but this is not the case so forcing the push is safe.

That said, if you ever do anything like that on a repo that we share, I'll find you.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235