« Back to Index

Git: multiple branches

View original Gist on GitHub

Tags: #git

git multiple branches.bash

# do some work
cd ./repo
git checkout some_feature

# I need to make a hotfix, but I don't want to disturn my messy 'some_feature' branch
# I don't want to have to stash things and get things cleaned up
# So I create a new 'worktree'
git worktree list
git worktree add ../hotfix

# open new terminal shell
# and make changes in my new 'hotfix' branch
cd ./hotfix

# merge my hotfix stuff back into 'main'
git checkout main
git merge hotfix

# ensure my original 'some_feature' is up-to-date with 'main'
cd ../repo
git rebase main

# clean-up the 'hotfix' working tree (this will delete that directory)
git worktree remove hotfix