It had been a habit of mine where I always do git pull/push origin [branchname]
for years because I push to master by accident once years. This week, I decided its time to up my git game and did some research on how to make the current checkout branch as the default upstream to push or pull.
This one is simple, just set global config push.default to current
git config --global push.default current
# after that I can simply push to my current checkout branch without type origin branchname
git push
This one is not as simple but would be great if I can find another solution.
# creating a new branch, make sure we track it too
git checkout -t -b my_branch
# switching to an existing branch, make sure we set the checkout branch to our upstream too
git checkout my_branch && git branch -u origin/my_branch
# and now we can pull without origin my_branch
git pull
[push]
default = current
[alias]
co = "!f() { git checkout $1 && git branch -u origin/$1; }; f"
https://stackoverflow.com/questions/14031970/git-push-current-branch-shortcut