Skip to content

Instantly share code, notes, and snippets.

@seisvelas
Created November 7, 2020 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seisvelas/bd38e65959b4859dc326843b960eb7f5 to your computer and use it in GitHub Desktop.
Save seisvelas/bd38e65959b4859dc326843b960eb7f5 to your computer and use it in GitHub Desktop.
Easier git pushes
#!/bin/bash
git push 2> /dev/null
if [ $? -eq 128 ]
then
$(git push 2>&1 \
| grep 'git push') 2>&1 \
| grep https \
| awk '{ print $2 }' \
| xargs firefox
fi
@seisvelas
Copy link
Author

seisvelas commented Nov 7, 2020

I spend a lot of time repeating this series of tasks:

alex@laptop:~/code/$ git push
fatal: The current branch other_branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin other_branch

alex@laptop:~/code/$ git push --set-upstream origin other_branch
Total 0 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'other_branch' on GitHub by visiting:
remote:      https://github.com/seisvelas/code/pull/new/other_branch
remote: 
To github.com:seisvelas/code.git
 * [new branch]      other_branch -> other_branch
Branch 'other_branch' set up to track remote branch 'other_branch' from 'origin'.

https://github.com/seisvelas/code/pull/new/other_branch

alex@laptop:~/code$ # Now I copy and paste the PR url from the previous command's output:
alex@laptop:~/code$ firefox https://github.com/seisvelas/code/pull/new/other_branch

Because copying/pasting the --set-upstream stuff is quicker than typing out the branch names.

I made this script to automate that process. Rename this script to 'push', chmod +x push, and move it to $HOME/.local/bin and then in any git branch you can conveniently push by just typing 'push' and let the magic happen.

So this is how I cope with being such a git noob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment