DEV Community

Jethro Larson
Jethro Larson

Posted on

Git push pitfalls to watch out for

Git is powerful but its relatively terse and obtuse api can make it hard to be sure what commands are really doing. Here are a couple pitfalls I've found over the years with git push that it's good to be aware of.

Pushing the wrong thing

You're probably familiar with git push but do you know all the assumptions that calling it without arguments is making?

git push is sugar for git push [default remote] HEAD:[HEAD's upstream branch]. So if your local branch's upstream is set to say 'master' you could accidentally overwrite master.

You can adjust the default behavior for git push by setting the push.default git config

Another trap is git push origin branch_name. It expands to git push origin branch_name:branch_name so if you're not on branch_name and you expect to push your current branch to remote branch_name you may be surprised (ask me how I know!).

Deleting a remote branch on accident

Here's a typo that can burn you hard

DON'T RUN THIS: `git push origin :branch_name'

You may assume that this means push your current branch up as "branch_name" but noooo, it actually will replace the remote branch with nothing, deleting the branch.

Top comments (0)