Are you tired of git NOT just pushing your branch and instead first asking to set origin for every new branch ?

Well, here is a command that can help you:

git push 2>&1 >/dev/null | tail -2 | grep 'git push' | awk '{split(\$0,a,\" \"); print a[5]}' | xargs -I{} git push --set-upstream origin '{}'

What this will do is first try `git push` and if there is an error it will get branch name and run git push — set-upstream origin branch-name.

of-course you are not going to write (or even copy past this every-time) so, what you can do is just create a shortcut (alias) for it. Something like this:

alias gph=”git push 2>&1 >/dev/null | tail -2 | grep ‘git push’ | awk ‘{split(\$0,a,\” \”); print a[5]}’ | xargs -I{} git push — set-upstream origin ‘{}’”

--

--

Here is how:

1. Script

Create a bash script, let’s say, ~/restart-runserver.sh and copy-paste following code:

2. Run

By running this script we can trick django development server into restarting it-self. To run:

bash ~/restart-runserver.sh

If you are asked to enter password every-time, you can change file permissions to avoid that. To change file permissions run:

sudo chmod 700 ~/restart-runserver.sh

3. Alias

Since we will be running this script a lot we can add an alias to help us easily run this. To add an alias, if using bash terminal, run:

echo "alias rst='bash ~/restart-runserver.sh'" >> ~/.bashrc

To add an alias, if using zsh terminal, run:

echo "alias rst='bash ~/restart-runserver.sh'" >> ~/.zshrc

Don’t forget to either source your rc file or restart your terminal for alias to work.

--

--