Git push to remote without creating local branch

Little extremely handy trick for Git.
If you need to modify something quickly in some(-body’s) branch, e.g. in in open PR on GitHub, you don’t need to usually create your local branch mirroring the remote one, right?
Instead, you just checkout into remote branch:

git checkout origin/branch-name

, do you fixes/changes, commit them and now, the tricky thing, how do you push?
As simple as:

git push origin HEAD:refs/heads/branch-name

You don’t have traces in your local branches, and you pushed your modifications.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.