Last active
February 8, 2019 04:19
-
-
Save octylFractal/d70b299803796fa9f4dca5c9cf9df9fb to your computer and use it in GitHub Desktop.
git psh (push -u -> psh): Push and set upstream if needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
red="$(tput setaf 1)" | |
green="$(tput setaf 2)" | |
cyan="$(tput setaf 6)" | |
reset="$(tput init)" | |
branch="$(git rev-parse --abbrev-ref HEAD)" | |
[[ $? == 0 ]] || { echo "$red"'git `psh` cannot work without a branch'"$reset"; exit 1;} | |
upstream="$(git rev-parse --abbrev-ref "$branch"'@{u}' 2>/dev/null)" | |
if [[ $? == 0 ]]; then | |
echo "${green}Pushing to $upstream...${reset}" | |
git push | |
else | |
echo "${cyan}Pushing to origin/$branch and setting as upstream...${reset}" | |
git push -u origin "$branch" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment