DEV Community

Jethro Larson
Jethro Larson

Posted on

2

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more