git Force Push

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 […]

The post git Force Push appeared first on David Walsh Blog.

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!

The post git Force Push appeared first on David Walsh Blog.


Print Share Comment Cite Upload Translate
APA
David Walsh | Sciencx (2024-03-28T14:28:15+00:00) » git Force Push. Retrieved from https://www.scien.cx/2022/08/19/git-force-push/.
MLA
" » git Force Push." David Walsh | Sciencx - Friday August 19, 2022, https://www.scien.cx/2022/08/19/git-force-push/
HARVARD
David Walsh | Sciencx Friday August 19, 2022 » git Force Push., viewed 2024-03-28T14:28:15+00:00,<https://www.scien.cx/2022/08/19/git-force-push/>
VANCOUVER
David Walsh | Sciencx - » git Force Push. [Internet]. [Accessed 2024-03-28T14:28:15+00:00]. Available from: https://www.scien.cx/2022/08/19/git-force-push/
CHICAGO
" » git Force Push." David Walsh | Sciencx - Accessed 2024-03-28T14:28:15+00:00. https://www.scien.cx/2022/08/19/git-force-push/
IEEE
" » git Force Push." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2022/08/19/git-force-push/. [Accessed: 2024-03-28T14:28:15+00:00]
rf:citation
» git Force Push | David Walsh | Sciencx | https://www.scien.cx/2022/08/19/git-force-push/ | 2024-03-28T14:28:15+00:00
https://github.com/addpipe/simple-recorderjs-demo