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
| Method | Features | Suitable Use |
|---|---|---|
| Pseudo-Remote (push) | Differential update, lightweight | Daily backups |
| Mirror (–mirror) | Complete copy of all information | Full backups a few times a month |
Recommended Local Workflow
- Create a branch at the start of work if needed
- Frequently add → commit as changes occur
- Check progress with diff / log
- If you make a mistake, use restore / reset / revert
- Push to pseudo-remote at the end of the day
- Periodically create complete backups with mirror
Quick Reference
| Purpose | Command |
|---|---|
| Check status | git status |
| Record changes | git add . → git commit -m "" |
| Create/switch branch | git switch -c / git switch |
| Restore file | git restore file |
| Undo last commit | git reset --soft HEAD^ |
| Complete rewind | git reset --hard HEAD^ |
| Revert to specific commit | git reset --hard ID |
| Undo preserving history | git revert ID |
| Reference past state | git switch --detach ID |
| Backup to pseudo-remote | git push backup main |
| Complete copy (mirror) | git clone --mirror src dest |