# Check Status

Before doing anything else always run git status.

git status
1

# Initialize Repo

Create a repo in current folder

git init
1

# 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
1
2
3
4
5
6

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`

1
2
3

# Stage files to be commited

git add file1 file2 file3...
git add .
git add -A | --all
git add '*.txt'
1
2
3
4

# Commit staged changes

Commit staged changes with a commit message

git commit -m "First commit"
1

# 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
1
2
3
4
5
6

# Remotes

git push -u origin master #Push master branch to origin and store params
git push
1
2
Updated: 1/3/2020, 6:56:10 PM