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

Yo…


This content originally appeared on DEV Community and was authored by Jethro Larson

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.


This content originally appeared on DEV Community and was authored by Jethro Larson


Print Share Comment Cite Upload Translate Updates
APA

Jethro Larson | Sciencx (2021-10-29T20:18:13+00:00) Git push pitfalls to watch out for. Retrieved from https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/

MLA
" » Git push pitfalls to watch out for." Jethro Larson | Sciencx - Friday October 29, 2021, https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/
HARVARD
Jethro Larson | Sciencx Friday October 29, 2021 » Git push pitfalls to watch out for., viewed ,<https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/>
VANCOUVER
Jethro Larson | Sciencx - » Git push pitfalls to watch out for. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/
CHICAGO
" » Git push pitfalls to watch out for." Jethro Larson | Sciencx - Accessed . https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/
IEEE
" » Git push pitfalls to watch out for." Jethro Larson | Sciencx [Online]. Available: https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/. [Accessed: ]
rf:citation
» Git push pitfalls to watch out for | Jethro Larson | Sciencx | https://www.scien.cx/2021/10/29/git-push-pitfalls-to-watch-out-for/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.