Table of Contents
This document lists Git commands used in solo-project development and CI releases. Commands assume the repository root as the working directory, remote name origin, and default branch main.
1. Repository and remotes
1.1 Clone and init
git clone git@github.com:user/repo.git
cd repo
# New local repository
git init
git remote add origin git@github.com:user/repo.git
1.2 Inspect remotes
git remote -v
git remote show origin
1.3 Remote URLs
SSH: git@github.com:user/repo.git
HTTPS: https://github.com/user/repo.git
Switch:
git remote set-url origin git@github.com:user/repo.git
git remote set-url origin https://github.com/user/repo.git
If SSH to GitHub times out, configure a proxy for github.com in ~/.ssh/config, or switch to HTTPS.
2. Daily commits
2.1 Basic workflow
git status # working tree and staging area
git diff # unstaged changes
git diff --staged # staged, uncommitted changes
git add <file> # stage one file
git add . # stage all changes in current directory
git commit -m "message" # commit
git log --oneline -10 # last 10 commits
2.2 Commit message prefixes (optional)
Many projects use prefixes to classify changes:
| Prefix | Meaning |
|---|---|
feat: | New feature |
fix: | Bug fix |
chore: | Build, config, dependencies |
docs: | Documentation |
Git does not require this format; follow team conventions when they exist.
2.3 Pull and push
git fetch origin # download remote refs, no merge
git pull origin main # fetch + merge into current branch
git push origin main # push current branch
git push -u origin main # first push, set upstream
3. Branches
3.1 Create and switch
git branch # list local branches
git branch -a # local and remote branches
git switch -c feat/dev # create and switch
git switch main # switch to existing branch
Equivalent (older Git versions):
git checkout -b feat/dev
git checkout main
3.2 Merge and delete
git switch main
git merge feat/dev # merge feat/dev into current branch
git branch -d feat/dev # delete merged local branch
git push origin --delete feat/dev # delete remote branch
git branch -d refuses to delete unmerged branches; use git branch -D to force.
4. Tags and releases
Some CI setups trigger builds or releases on tag push. Tag names usually match the version in package.json, tauri.conf.json, or similar.
4.1 Create and push
git tag v0.1.0 # lightweight tag on HEAD
git tag -a v0.1.0 -m "release 0.1.0" # annotated tag
git push origin v0.1.0
Inspect tags:
git tag
git show v0.1.0
4.2 Delete and retag
To re-trigger CI with the same version number, delete the tag locally and on the remote, then recreate:
git tag -d v0.1.0
git push --delete origin v0.1.0
git tag v0.1.0
git push origin v0.1.0
If a GitHub Release is linked to that tag, delete the Release on the web UI before retagging.
5. Amend and undo
5.1 Amend last commit
Fold new changes into the most recent commit (the commit hash changes):
git add .
git commit --amend --no-edit # keep existing message
git commit --amend -m "new message" # change message
After amending a commit that was already pushed, use git push --force-with-lease. Use with care on shared branches.
5.2 reset modes
git reset --soft HEAD~1 # move HEAD back; changes stay staged
git reset --mixed HEAD~1 # move HEAD back; changes unstaged (default)
git reset --hard HEAD~1 # move HEAD back; discard staged and working changes
| Mode | Commit history | Staging area | Working tree |
|---|---|---|---|
--soft | Rewound | Kept | Kept |
--mixed | Rewound | Cleared | Kept |
--hard | Rewound | Cleared | Cleared |
5.3 Discard uncommitted changes
git restore <file> # restore one file to HEAD
git restore . # restore all tracked files
git clean -fd # remove untracked files and directories
Equivalent:
git checkout -- <file>
git reset --hard
reset --hard and clean -fd cannot recover uncommitted work.
6. Stash
Temporarily store working-tree changes to switch branches or pull:
git stash # save changes; working tree becomes clean
git stash list # list entries
git stash pop # apply latest and remove from list
git stash apply # apply without removing
git stash drop # drop one entry
By default, stash does not include untracked files. Include them with:
git stash -u
7. .gitignore
7.1 Rules not taking effect
Files added before an ignore rule was written remain tracked:
git rm -r --cached .
git add .
git commit -m "chore: apply gitignore"
git rm -r --cached removes from the index only; files on disk are kept.
7.2 Common entries
node_modules/
dist/
.env
*.jks
.DS_Store
8. Merge conflicts
After git merge or git pull, Git inserts markers in conflicted files:
<<<<<<< HEAD
content on current branch
=======
content from incoming branch
>>>>>>> branch-name
Resolution:
- Open the file and find
<<<<<<<. - Keep the desired code; remove markers and unwanted sections.
git add <file>to mark resolved.git committo finish the merge.
Abort the merge:
git merge --abort
9. Secrets and history
Do not commit .env, key files (e.g. .jks), or private keys. git rm plus a new commit removes the file from the current tree only; it may still exist in older commits.
For secrets already pushed to a remote, rewrite history with git filter-repo or BFG Repo-Cleaner, and rotate the exposed credentials.
For unpushed local mistakes, git reset and recommit is sufficient.
10. Troubleshooting
git push rejected (non-fast-forward)
The remote has commits you lack. Run git pull (or git pull --rebase), then push again.
detached HEAD
HEAD points at a commit, not a branch. Return to a branch:
git switch main
Inspect a specific commit
git show <commit-hash>
git diff <commit-hash>^ <commit-hash>
History of one file
git log --oneline -- path/to/file