Local-Only Git Workflow Guide

What I Learned

I organized a workflow for using Git solely locally, without using remotes like GitHub, aimed at Git beginners and individual developers. Since Git inherently keeps all history locally, understanding local Git before learning about remotes makes it easier to handle and less confusing. Backups (pseudo-remote/mirror) are possible even within local environments.

Details

Benefits of Using Git Locally Only

  • Fewer concepts to learn, easier to study
  • No risk of bothering others
  • Can focus on Git’s essence (managing change history)

1. Basic Operations and Workflow

1-1. Repository Creation and Status Checks

1git init
2git status

1-2. Recording Changes Flow

1git add .
2git commit -m "work description"

1-3. Checking Status and History

1git diff
2git log --oneline --graph --decorate

1-4. Branch Operations

1git switch -c feature
2git switch main
3git branch -d feature

2. Reverting to Past Versions (Recovery Commands)

2-1. Restore Files Only

1git restore filename

2-2. Undo the Last Commit (Keep Work Contents)

1git reset --soft HEAD^

2-3. Rewind Commits and Changes (Destructive)

1git reset --hard HEAD^

2-4. Revert to a Specific Commit

1git reset --hard <commit-id>

2-5. Undo Without Breaking History

1git revert <commit-id>

2-6. Reference Past State

1git switch --detach <commit-id>

3. Backup (Local Pseudo-Remote + Mirror)

Git “remotes” don’t have to be URLs; you can register local folders as remotes.

3-1. Backup with Pseudo-Remote (Bare Repository)

Create backup side:

1mkdir /path/to/backup
2cd /path/to/backup
3git init --bare

Register from original repository:

1git remote add backup /path/to/backup

Execute backup:

1git push backup main

3-2. Complete Backup (Mirror)

Using --mirror, you can copy all branches, tags, and settings of a repository entirely.

Create mirror:

1git clone --mirror /path/to/project /path/to/backup-mirror

3-3. How to Use Pseudo-Remote vs Mirror

MethodFeaturesSuitable Use
Pseudo-Remote (push)Differential update, lightweightDaily backups
Mirror (–mirror)Complete copy of all informationFull backups a few times a month
  1. Create a branch at the start of work if needed
  2. Frequently add → commit as changes occur
  3. Check progress with diff / log
  4. If you make a mistake, use restore / reset / revert
  5. Push to pseudo-remote at the end of the day
  6. Periodically create complete backups with mirror

Quick Reference

PurposeCommand
Check statusgit status
Record changesgit add .git commit -m ""
Create/switch branchgit switch -c / git switch
Restore filegit restore file
Undo last commitgit reset --soft HEAD^
Complete rewindgit reset --hard HEAD^
Revert to specific commitgit reset --hard ID
Undo preserving historygit revert ID
Reference past stategit switch --detach ID
Backup to pseudo-remotegit push backup main
Complete copy (mirror)git clone --mirror src dest

References