Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisribe/218e98590ae7be1e294ac9fc3562c9ce to your computer and use it in GitHub Desktop.
Save chrisribe/218e98590ae7be1e294ac9fc3562c9ce to your computer and use it in GitHub Desktop.
Alias 'mainup' for Updating and Keeping 'main' Branch Up-to-Date While on Working Branch
# Set up a Git alias called 'mainup' that updates the 'main' branch and brings it up-to-date while staying on the current working branch
# Run the following command to set up the alias:
git config --global alias.mainup '!git rev-parse --abbrev-ref HEAD > .git/CURRENT_BRANCH && git checkout main && git pull && git checkout $(cat .git/CURRENT_BRANCH) && rm .git/CURRENT_BRANCH'
# Now you can update the 'main' branch and bring it up-to-date while staying on your working branch by running the 'mainup' command:
git mainup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment