Git
From Supernifty
Basic
- git init = create a repository in .
- git add (files) = add files to staging
- git commit -m 'message' -a = stage changes and commit snapshot
- git clone repo = copy repo locally
- git tag -a 'version' = tag
- git rm file - unstage and remove file
Branching
- git branch = list branches
- git branch newbranch = create branch
- git checkout newbranch = switch to branch
- git branch -d newbranch = delete branch
- git merge newbranch = merge newbranch into current branch
Status
- git diff = changes that have not been staged
- git diff --cached = changes that have been staged
- git status -s = uncommitted changes summary
- git log = commit history
- git log --oneline = short commit history
Undo a mistake
- git reset HEAD -- filename = unstage filename
Remote
- git remote -v = list remote aliases
- git pull = git fetch; git merge
- git pull remote
- git push remote branch = push branch to remote
- for github this is typically git push origin master
A workflow
- git checkout -b featurename
- Add files, make changes, etc
- git diff # what's changed?
- git commit -a # commit to branch
- git checkout master # back to main branch
- git merge featurename # merge feature back to master
- git commit -a # commit
- git branch -d featurename # delete branch