Git commands I find useful
I can never remember these so here they are:
# Check out an existing local branch:
git checkout <local-branch>
# Create a new branch from the currently checked out branch and check it out:
git checkout -b <new-branch>
# Switch to a new local branch, and pull changes from a specific remote branch:
git switch -c <new-local-branch> origin/<remote-branch>
# Same as above but without tracking the remote:
git switch --no-track -c <new-local-branch> origin/<remote-branch>
# Get the latest changes from a remote branch:
git pull origin <remote-branch>
# Checkout a tagged branch and create a new branch from it.
# If a branch has been tagged you can see the code at a particular point:
git checkout tags/<tag-name> -b <new-branch-name>
# Delete a local branch:
git branch --delete <local-branch>
# Delete a remote branch:
git push origin --delete <remote-branch>
# Get your local branch to match your remote branch.
git reset --hard origin/<remote-branch>