Skip to content

cmlpolymath/git-gud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Git Gud

A practical, terminal-first Git reference you can use as a quick professional guide.


Git mental model

Git has four main states:

  • Working directory: your current files
  • Staging area: what goes into the next commit
  • Local repository: your local commit history
  • Remote repository: shared history on GitHub/GitLab/etc.

The professional habit is simple:

check → review → stage → commit → sync → push


Repository lifecycle at a glance

flowchart TD
    %% Styles
    classDef setup fill:#e1f5fe,stroke:#01579b,stroke-width:2px;
    classDef dev fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px;
    classDef sync fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef cleanup fill:#ffebee,stroke:#b71c1c,stroke-width:2px;
    classDef decision fill:#ffcc80,stroke:#e65100,stroke-width:2px;
    classDef startend fill:#f3e5f5,stroke:#4a148c,stroke-width:4px,color:#4a148c;

    %% Setup Phase
    subgraph Setup_Phase ["🚀 Setup Phase"]
        A((Spin Up Environment)):::startend
        B[Create or Clone Repository]:::setup
    end

    %% Development Phase
    subgraph Dev_Phase ["💻 Development Phase"]
        C[Create Feature Branch]:::dev
        D[Edit Files]:::dev
        E{Review Changes?}:::decision
        F[Stage Changes]:::dev
        G[Commit with Message]:::dev
    end

    %% Sync & Integration Phase
    subgraph Sync_Phase ["🔄 Sync & Integration"]
        H[Fetch / Pull Latest]:::sync
        I{Rebase or Merge<br/>Conflicts?}:::decision
        J[Resolve Conflicts]:::sync
        K[Push Branch]:::sync
        L[Open Pull Request]:::sync
        M{PR Review}:::decision
        N[Merge PR]:::sync
    end

    %% Cleanup Phase
    subgraph Cleanup_Phase ["🧹 Cleanup"]
        O[Pull Updated Main]:::cleanup
        P[Delete Old Branches]:::cleanup
        Q((Archive / Spin Down)):::startend
    end

    %% Connections
    A --> B
    B --> C
    C --> D
    D --> E
    E -- "Ready" --> F
    E -- "Needs Work" --> D
    F --> G
    G --> H
    H --> I
    I -- "No Conflicts" --> K
    I -- "Conflicts" --> J
    J --> F
    K --> L
    L --> M
    M -- "Approved" --> N
    M -- "Changes Requested" --> D
    N --> O
    O --> P
    P --> Q

    %% Legend (optional)
    Legend[<b>Legend</b><br/>🟦 Setup   🟩 Development<br/>🟨 Sync   🟥 Cleanup<br/>🟧 Decision   🟪 Start/End]:::legend
    classDef legend fill:#f5f5f5,stroke:#666,stroke-dasharray: 5 5,color:#333;
Loading

1) Spin up a repository

Create a brand new local repo

mkdir my-project
cd my-project
git init
git branch -M main

Add files and make the first commit

git add .
git commit -m "Initial commit"

Add a remote and push

git remote add origin git@github.com:username/repo-name.git
git push -u origin main

Clone an existing repo

git clone git@github.com:username/repo-name.git
cd repo-name

2) Auto-pilot: create and maintain a repo entirely from the terminal

This section is the closest thing to a clean terminal-only workflow for spinning up and maintaining a repo professionally.

A. First-time machine setup

Verify Git and GitHub CLI

git --version
gh --version

Set your Git identity

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Set a few sane defaults

git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global fetch.prune true
git config --global rebase.autoStash true
git config --global push.default simple

Check your configuration

git config --global --list

Authenticate GitHub CLI

gh auth login
gh auth status

B. Auto-pilot: create a new repo from an existing project folder

Go into your project directory:

cd /path/to/your/project

Initialize Git:

git init
git branch -M main

Create a .gitignore:

nano .gitignore

Example .gitignore starter:

__pycache__/
*.pyc
.venv/
.env
.DS_Store
.vscode/
.idea/
dist/
build/
*.log

Check what files exist:

git status -u

Stage and commit:

git add .
git commit -m "v0.1 initial project scaffold"

Create the GitHub repo from the terminal and push in one step:

gh repo create repo-name --private --source=. --remote=origin --push

Check the remote:

git remote -v

That is the cleanest terminal-only path.


C. Auto-pilot: if the GitHub repo already exists

Initialize locally:

git init
git branch -M main

Add files:

git add .
git commit -m "Initial commit"

Add the remote manually:

git remote add origin git@github.com:username/repo-name.git

Verify:

git remote -v

Push:

git push -u origin main

D. Auto-pilot: daily maintenance flow

This is the professional terminal habit loop:

git status -sb
git diff
git add -p
git commit -m "feat: describe change"
git fetch origin
git rebase origin/main
git push

If working directly on main in a solo repo, the loop is usually:

git status -sb
git add .
git commit -m "Describe update"
git pull --rebase
git push

E. Auto-pilot: start a feature branch and keep it healthy

Create and switch:

git switch -c feature/my-change

Work normally:

git status -sb
git add -p
git commit -m "feat: add my change"

Sync with latest main:

git fetch origin
git rebase origin/main

Push branch:

git push -u origin feature/my-change

After merge, clean up:

git switch main
git pull --rebase
git branch -d feature/my-change
git push origin --delete feature/my-change

F. Auto-pilot: repo shutdown / spin-down

If the repo is done and you want to clean it up:

Clean merged local branches

git switch main
git pull --rebase
git branch --merged
git branch -d branch-name

Remove stale remote-tracking refs

git fetch --prune

Detach local folder from GitHub remote

git remote remove origin

Remove Git tracking entirely but keep files

rm -rf .git

Delete the local repo folder entirely

cd ..
rm -rf repo-name

3) Professional command flow: spinning up, maintaining, and spinning down a repository

flowchart TD
    A[Open Terminal in Project Folder] --> B[git init]
    B --> C[Create .gitignore]
    C --> D[git add .]
    D --> E[git commit -m Initial commit]
    E --> F[gh auth login]
    F --> G[gh repo create repo-name --source=. --remote=origin --push]
    G --> H[Daily Work]
    H --> I[git status]
    I --> J[git add / git add -p]
    J --> K[git commit]
    K --> L[git fetch origin]
    L --> M[git rebase origin/main]
    M --> N[git push]
    N --> O[Repo Complete]
    O --> P[Cleanup branches]
    P --> Q[Archive / remove remote / delete local copy]
Loading

4) Core everyday commands

Status and inspection

git status
git status -sb
git remote -v
git branch
git branch -vv

Review changes

git diff
git diff --staged
git show

Stage files

git add .
git add FILE
git add -p
git restore --staged FILE

Commit changes

git commit -m "Short message"
git commit
git commit --amend

Push and pull

git pull --rebase
git push
git push -u origin main

Fetch without changing your branch

git fetch origin
git fetch --all --prune

5) Branching

Create and switch branch

git switch -c feature/new-work

Switch branches

git switch main
git switch feature/new-work

List branches

git branch
git branch -a
git branch -vv

Rename current branch

git branch -M main

Delete a branch

git branch -d feature/new-work
git branch -D feature/new-work

6) History and investigation

Compact history

git log --oneline --decorate --graph --all

Show recent commits

git log -n 10

Show one commit

git show <commit>

See who changed a file

git blame path/to/file

7) Undo and recovery

Discard unstaged changes

git restore FILE
git restore .

Unstage without deleting work

git restore --staged FILE
git restore --staged .

Revert with a new commit

git revert <commit>

Reset local history

git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1

Recover lost work

git reflog

8) Rebase, merge, and sync

Preferred professional sync pattern

git fetch origin
git rebase origin/main

Merge a branch into current branch

git merge feature/my-change

Interactive rebase to clean commits

git rebase -i HEAD~5

If conflicts happen

git status
# fix files
git add .
git rebase --continue

Abort if needed:

git rebase --abort

9) Stash

Useful when you need to pause work quickly.

git stash
git stash push -m "wip"
git stash push -u -m "wip including untracked"
git stash list
git stash pop
git stash apply stash@{0}

10) Remote management

Show remotes

git remote -v

Add remote

git remote add origin git@github.com:username/repo-name.git

Change remote URL

git remote set-url origin git@github.com:username/repo-name.git

Remove remote

git remote remove origin

11) Tags and releases

Create a tag

git tag v1.0.0
git tag -a v1.0.0 -m "Release v1.0.0"

Push tags

git push origin v1.0.0
git push origin --tags

Delete tags

git tag -d v1.0.0
git push origin --delete v1.0.0

12) Cleanup and maintenance

Prune stale refs

git fetch --prune

Show merged branches

git branch --merged

Remove untracked junk safely

git clean -nfd
git clean -fd

Garbage collection

git gc

13) Terminal-only quick recipes

Recipe: create a brand new repo from a project folder

cd /path/to/project
git init
git branch -M main
nano .gitignore
git add .
git commit -m "Initial commit"
gh auth login
gh repo create repo-name --private --source=. --remote=origin --push
git remote -v
git status -u

Recipe: push local repo to an already-created GitHub repo

cd /path/to/project
git init
git branch -M main
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:username/repo-name.git
git remote -v
git push -u origin main

Recipe: normal daily update

git status -sb
git add -p
git commit -m "fix: update logic"
git pull --rebase
git push

Recipe: cleanly finish a feature branch

git switch main
git pull --rebase
git switch -c feature/my-work
# make changes
git add .
git commit -m "feat: add new work"
git fetch origin
git rebase origin/main
git push -u origin feature/my-work

Recipe: clean up after merge

git switch main
git pull --rebase
git branch -d feature/my-work
git push origin --delete feature/my-work
git fetch --prune

14) Commands from your original list, corrected

You had the right idea, but a few commands needed cleanup.

Corrected terminal-first version

git init
nano .gitignore
git add .
git commit -m "v0.1 of project"
git config --global --list
gh --version
gh auth login
gh repo create repo-name --private --source=. --remote=origin --push
git remote -v
git branch -M main
git push -u origin main
git status -u

Important corrections

This is wrong:

git branch push -u origin main

Use:

git push -u origin main

This may be redundant if gh repo create ... --remote=origin --push already succeeded:

git remote add origin git@github.com:username/repo-name.git

That command is only needed when you are adding the remote manually.


15) Professional habits that make you look sharp

Use these consistently:

  • Run git status -sb constantly
  • Use git add -p instead of blindly staging everything when changes are mixed
  • Prefer git pull --rebase over noisy merge commits for your own feature branches
  • Use clear commit messages
  • Verify remotes with git remote -v
  • Clean merged branches regularly
  • Use gh repo create when starting a GitHub-backed repo from terminal
  • Learn reflog before you need it

16) Commit message examples

A simple professional pattern:

feat: add resume tailoring pipeline
fix: correct branch push instructions
docs: expand git cheat sheet
refactor: simplify repo bootstrap flow
chore: update gitignore

17) The shortest possible “look professional” workflow

If you remember nothing else, remember this:

git status -sb
git add -p
git commit -m "feat: meaningful message"
git fetch origin
git rebase origin/main
git push

That sequence alone will cover a huge percentage of professional Git usage cleanly.

If you want, I can turn this into a polished README.md file with cleaner section anchors and copy-paste formatting for GitHub.

About

Here's how to use git...really, really good.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors