Another time Git left me speechless
Working with Git is an activity that requires an humble approach, everything you do can be wrong in a situation you couldn’t think of and Git pretty much tries to save you from all what may be out there.
To me this behavior resemble pretty well the Rust compiler. Whenever rustc refuses to compile my script there is a reason that is explained in a short line of output and more often than not the compiler output something on the line of “Ehi you want to do A, you can do it like these…“.
Damn compiler, always bitching that I have to change my code, you already know what I want to do and you give hint, do it yourself!
[me every time I forget a
Box<T>
]
This time I was rebasing the forgotten appcache branch of a project onto the master, all was good, there was a simple merge conflict; open vim, edit, save, git add
and a git rebase --continue
later I was ready to update the project on the remote repository.
Except that the remote refused to update!
I sit there, the pc on my lap, wondering if using git push --force
was a viable way out of the mess I did or if I should really delete the remote branch and restart over when the need to learn how to properly resolve this conflict stepped over.
I know of a page that collect the solutions to this very kind of problems but this time is different, I want to know why Git refuse to do a simple push.
And here I am, lost in the help page of git push
, searching for the term fast-forward
when I finally see it.
--force-with-lease
--force-with-lease
is an option of git push
that suits my case perfectly. I have a remote branch remote/appcache and a local branch appcache, I rebased appcache on the local master and now the very same two branches, appcache and remote/appcache are considered a danger because I want to move forward a remote branch.
Basically I have to rebase something already published, something on which someone could have worked! If I update the remote branch and move it to the HEAD of my master branch someone could lose their progress.
Imagine someone was working with the very same branch and I do not have their progress, pushing my latest commit, rebased on the top of the master branch, to the remote delete all of their work!
Updating my remote history moving forward a branch can be done if I am really sure no one touched it, this can be done with --force-with-lease
. Checking the tip of the two branch in question, the local rebased and the remote, assure Git that the two branches are the very same history and that we can me it forward without losing someone’s work during the process.