Skip to content

Commit

Permalink
Helper script to update and switch to the main branch of a project
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKnarf committed Jun 5, 2024
1 parent a17fde7 commit ebf4376
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/git-main
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Based on: https://stackoverflow.com/questions/3216360/merge-update-and-pull-git-branches-without-using-checkouts/17722977#17722977

show_help() {
echo "usage: git main [-h]"
echo ""
echo " Update main branch and then switch to it."
echo " This way I shouldn't need to pull after switching branches."
echo " This shouldn't trigger a hot-reload if I am running something in hot-reload mode and are switching back to main after merging in a feature branch."
}

if [[ "$1" == "-h" ]]; then
show_help
exit 0
fi

# Can't run `git fetch origin main:main` if I'm on the main branch
# This isn't really a problem since the command is meant to be used when switching from a feature branch to `main`
# But as an extra convenience we run this before
git checkout --quiet -d HEAD

# Update the main branch before switching to it
# Assuming that the remote is called `origin`
git fetch origin main:main

git checkout main

0 comments on commit ebf4376

Please sign in to comment.