A concise, copy-paste reference for everyday Git commands and workflow tips.
git-guide/
βββ README.md β this guide
βββ main.java β minimal Java example (ProcessBuilder + Git)
βββ main.py β minimal Python example (subprocess + Git)
# clone & enter
git clone https://github.com/ryanzhangofficial/git-guide.git
cd git-guide
# create a feature branch
git switch -c <feature>
# work β stage β commit
git add .
git commit -m "feat: <message>"
# sync with main before pushing
git fetch origin
git rebase origin/main # or: git merge origin/main
# push & open PR
git push -u origin <feature>
| Goal | Command |
|---|---|
| List branches | git branch -a |
| Rename current branch | git branch -M <new> |
| Delete local branch | git branch -d <name> |
| Delete remote branch | git push origin --delete <name> |
Switch & create (-b) |
git checkout -b <name> / git switch -c <name> |
# create annotated tag
git tag -a v1.0 -m "First stable release"
# push a single tag
git push origin v1.0
# delete & recreate tag
git tag -d v1.0
git push origin --delete v1.0
git tag -a v1.0 -m "Retagged v1.0"
git push origin v1.0
git rebase -i HEAD~N # squash or reword last N commits
git commit --amend # edit most recent commit
git reflog # recover lost refs / commits
git stash # shelve uncommitted changes
| File | Purpose |
|---|---|
| main.py | Demonstrates calling Git commands from Python via subprocess |
| main.java | Same concept using Javaβs ProcessBuilder |
- Fork β branch β PR.
- Keep code comment-free (per project preference).
- Use commit style:
<type>: <subject>where type βfeat,fix,docs,refactor,chore.
MIT