Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 29, 2021 08:18 pm GMT

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.


Original Link: https://dev.to/jethrolarson/git-push-pitfalls-to-watch-out-for-1im4

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To