1

I have been using git push origin branch-name for a while even for the fact that I am already on the branch-name branch (check with git branch).

So I wonder is there something like git push origin this sorta command so that I can push change into my branch that I am already on, without have to do the two step process of git branch and then the copy and paste of branch name every time?

Been doing this for a year and silly enough I think its time for a better way to do this to save my time. Thanks!

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121
  • 3
    i think simply doing `git push` works. edit: Your remote must be set and current branch must be tracked to remote branch.. which i think happens automatically.. – Vasif Aug 21 '17 at 23:13
  • 1
    Possible duplicate of [Default behavior of "git push" without a branch specified](https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified) – Charles Durham Aug 21 '17 at 23:14
  • @Vasif hum.... I did once with `git push origin` and it did not work, trying `git push` did not come to my mind at that time lol I am going to try it tomorrow! thanks – ey dee ey em Aug 22 '17 at 00:42

2 Answers2

2

I think time has come for you to become more hackish to dominate the command line and guess what...its the ZSH shell that will enable you to type

ggpush

which will be converted to:

git push origin <current-branch>

and similarly ggpull will result in git pull origin <current-branch>

Easy, isn't it?!

You just need to enable the git plugin in .zshrc like:

plugins=(git)

to hack into this.

You will find the complete list of git shortcuts on the wiki or locally in

~/.oh-my-zsh/plugins/git/git.plugin.zsh

The complete plugins list will help you unleash the full power of this shell of huge popularity (58k+ github stars!)

Wasif Hossain
  • 3,900
  • 1
  • 18
  • 20
1

You can configure git to push to the current branch by running this command...

git config --global push.default current

Then you only need to include a branch name when you want to push to a different branch.

dougtesting.net
  • 571
  • 4
  • 9
  • Wow! Wonder why git does not make it to be default! that makes so much sense. Will try it for sure! Thanks – ey dee ey em Aug 22 '17 at 00:41
  • @Ezeewei Git is flexible. In `git push :`, `remote`, `commit-ish` or `remote_ref` can be omitted partially or fully according to the configuration. Git allows users to define the default behaviour. – ElpieKay Aug 22 '17 at 05:02