Skip to content

Instantly share code, notes, and snippets.

@maciakl
Last active January 3, 2025 06:01
Show Gist options
  • Save maciakl/1584387 to your computer and use it in GitHub Desktop.
Save maciakl/1584387 to your computer and use it in GitHub Desktop.
Git Workflow
# GIT WORKFLOW
# (c) Luke Maciak
# Initializing:
git clone user@host:/repo.git
git init
# Workflow
git add .
git commit -m "message"
git commit --amend # amend changes to previous commit
git push # push to upstream
# Remotes
git remote add origin user@host:/repo.git # add upstream remote
git push -u origin main # set default upstream for push
# Stashing (when you made changes and forgot to pull for example):
git stash # saves current state for later use
git stash apply # restores/merges stashed state
git stash unapply # reverts stash apply
# Undoing Things
git reset --soft HEAD~1 # move last commit back into staged
git reset --hard HEAD~1 # revert last commit discarding everything
git restore <file> # drops unstaged changes to a single file
git restore -- . # drop all unstaged changes
# Branching:
git switch -c branchname # create new branch
git switch branchname # switch back to master
git branch -d branchname # delete branch
git push origin branchname # push branch
git pull origin <branchname> # for specific branch
git merge branchname # merge branchname into current
# Tagging:
git tag -a 1.1 -m "tag description" # regular tag
git tag 1.1 # lightweight tag
git tag 1.1 9fceb02 # tag specific commit
git push --tags # push tags
git tag -d 1.0 # delete local tag
# Diffs
git diff # diff against working area
git diff --staged # dif against staged files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment