git Force Push

By  on  

Rebasing is a frequent task for anyone using git. We sometimes use rebasing to branch our code from the last changes or even just to drop commits from a branch.

Oftentimes when trying to push after a rebase, you'll see something like the following:

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Commonly developers will use the --force or -f flags during a push to force pushing code changes:

git push origin my-branch --force
# or
git push origin my-branch -f

I was recently surprised to find out that you could also prefix the branch name with + to force a push:

git push origin +my-branch

The + syntax is interesting but doesn't seem intuitive so it's not a practice I'd use, but that doesn't mean you shouldn't!

Recent Features

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

  • By
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

Incredible Demos


    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!