what exactly happens when you git push with --force?
I have been searching the web for about an hour now, and the most relevant answer I can find is:
Same as [git push], but force the push even if it results in a non-fast-forward merge. Do not use the --force flag unless you’re absolutely sure you know what you’re doing.
-source from https://www.atlassian.com/git/tutorial/remote-repositories#!push
I understand this well enough, I think, but to me this is like saying git push --force
will force a push. Despite my searching, I can't find anything really concrete that outlines the process involved in a force push.
Hypothetically, I have a main repo set up called git@heroku.com:my-app.git, and a mirror of that repo set up on Heroku for staging called git@heroku.com:my-app-staging.git.
I have created a local branch called 'new_changes', done work, and pushed to staging from this branch.
I didn't like the results, so I abandoned the project, set up a new branch called 'more_new_changes', did some work, tested it locally, merged with master, and tried to push to staging, just to make sure staging is up-to-date.
My push tells me...
Pushing to git@heroku.com:my-app-staging.git
Fetching repository, done.
To git@heroku.com:my-app-staging.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:my-app-staging.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.
I don't want to merge the code that's on staging into my local master branch- in fact, I want that staging code to be gone. (Obviously, the branches would be titled with hashes, but for the sake of argument) I figure that if my staging looks like
push079
->push080
->new_changes(HEAD)
and my local looks like
push079
->push080
->more_new_changes(HEAD)
and I decide to push to staging using --force, then the result would be a staging branch that looks like
push079
->push080
->more_new_changes(HEAD)
Alternatively it could look more like
push079
->push080
->new_changes
\
>more_new_changes(HEAD)
but if I'm wrong, and it just squashes the two together, and I wind up with something like
push079
->push080
->new_changes
->more_new_changes(HEAD)
then I lose the continuity of having a staging repo that mirror-reflects my production repo.
So, what actually happens behind the scenes when you push using --force?