Git Workflow - Practical Operations

Created by: Graham Ovenden, Last modification: 3 May 2026

Still getting used to git having been a long time Hg user and while everything is now on github, using it on the command line is not something I do every day. VSCode handles a lot of the stuff, but building a better archive of the various systems and mirroring them via git has proven useful recently so here are some notes to help especially after I screw up!

Identity setup

git config --global user.name "Lester Caine"
git config --global user.email "lester@lsces.co.uk"
git config --global init.defaultBranch production
git config --global core.editor "nano"

Fix last commit

# Fix message only
git commit --amend -m "correct message"

# Fix author
git commit --amend --reset-author

# After amending - force push needed
git push --force origin production

Sync after force push

# On other machines after a force push rewrote history
git fetch origin
git reset --hard origin/production

Renaming files

git mv oldname newname
git commit -m "rename reason"

Disabling files

git mv nginx/conf.d/site.conf nginx/conf.d/site.conf.off
git commit -m "site disabled - reason"

Daily workflow

git pull                    # get latest
# make changes
git status                  # check what changed
git diff filename           # see exactly what changed
git add filename            # stage specific file
git add .                   # stage everything
git commit -m "what and why"
git push

Oops - undo things

git restore filename        # discard uncommitted changes
git reset HEAD~1            # undo last commit keep changes
git reset --hard HEAD~1     # undo last commit discard changes

Investigating history

git log --oneline           # compact history
git log --oneline -10       # last 10 commits
git show commitHash         # see what a commit changed
git diff HEAD~1 filename    # what changed in last commit

Branch management

git branch -vv              # show branches and tracking
git branch -m oldname newname  # rename branch

Remote management

git remote -v                              # show remotes
git remote add origin url                  # add remote
git remote set-url origin newurl           # change remote url
git remote remove origin                   # remove remote

Developed with Claude AI assistance - Anthropic - April 2026