- GitHub's Get Started Course
- Oh Shit, Git!?!
- Git Butler
- Axosoft - Learning Git
- Oh shit, git!
- First Aid git
- Productive Git for Developers
- Frontend Masters: Git in Depth by Nina Zakharenko - slides and repo
- FreeCodeCamp's Course
Check Status
Before doing anything else always run git status.
git status
Initialize Repo
Create a repo in current folder
git init
Branches
Create separate branches for any task/feature you begin. Then do your work and commits, pull and merge before merging the branch back into the master branch when all done.
git branch # Lists local branches. Current marked with asterisk
git branch branchname # Create a new local branch
git branch -d branchname # Delete branch
git branch -D branchname # Delete branch forcefully
git checkout branchname # Check out named branch
git checkout -b branchname # creates and checks out
Merge branches by first switching to the branch you want to merge TO. Then run git merge using the name of the FROM branch.
git checkout `master`
git merge `branchname`
Stage files to be commited
git add file1 file2 file3...
git add .
git add -A | --all
git add '*.txt'
Commit staged changes
Commit staged changes with a commit message
git commit -m "First commit"
Undo
git checkout <filename> # Revert local changes back to latest commited ver
git reset <filename> # remove change from staging area
git reset --hard head # Clear uncommitted working dir changes
git reset head~ # Undo latest commit and put back in working dir
git reset --hard head~ # Undo latest commit completely
git reset head@{1} # Undo last reset
Remotes
git push -u origin main #Push master branch to origin and store params
git push