Last active
January 30, 2023 23:02
-
-
Save guinunez/4525308 to your computer and use it in GitHub Desktop.
Herramienta para realizar los comandos mas comunes de git en secuencia:- Verifica que esté sobre un repositorio- Agrega y quita los archivos modificados- Hace el commit pidiendo el mensaje- Realiza el pull- Si detecta un branch remoto upstream, hace el merge- Si el automerge falla, llama a mergetool (hay que volver a correr syncme despues de eso…
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 | |
# Tool to perform common Git commands in sequence: | |
# - Verifies that you are in a Git repository | |
# - Adds and removes modified files | |
# - Commits with a message | |
# - Performs a pull | |
# - If a remote upstream branch is detected, performs a merge | |
# - If the automatic merge fails, calls the mergetool (you need to run syncme again after that) | |
# - This version should be compatible with MacOS | |
git status | |
ERR=$? | |
if [[ $ERR != 0 ]]; then | |
echo ">>> Error code: $ERR" | |
echo ">>> Exiting syncme script" | |
exit | |
fi | |
CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) | |
ALIAS=${1:-origin} | |
BRANCH=${2:-$CURRENT_BRANCH} | |
read -p "Commit description: " DESC | |
echo "> git add ." | |
git add . | |
echo "> git add -u" | |
git add -u | |
echo "> git commit -m \"$DESC\"" | |
git commit -m "$DESC" | |
echo "> git pull $ALIAS $BRANCH" | |
git pull $ALIAS $BRANCH | |
# Check for remote upstream | |
if git branch -a | grep -q 'remotes/upstream'; then | |
echo "> git fetch upstream" | |
git fetch upstream | |
echo "> git merge upstream/$BRANCH" | |
MERGESTATUS=$(git merge upstream/$BRANCH) | |
echo MERGESTATUS | |
if echo "$MERGESTATUS" | grep -q "Automatic merge failed"; then | |
echo "> git mergetool" | |
git mergetool | |
echo ">>> Please run this command again if you finished merging correctly" | |
exit | |
fi | |
echo "> git push $ALIAS $BRANCH" | |
git push $ALIAS $BRANCH | |
echo ">>> Merge successful, you can make a pull request now" | |
else | |
echo "> git push $ALIAS $BRANCH" | |
git push $ALIAS $BRANCH | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment