General

Find out what version is running

git --version

Create repo

git init REPO-NAME

// Or when in a folder that's already created locally
git init

Show the current status of the git repository

git status

View git commits

git log

 

Adding and committing

Add files

// Add individual file
git add NAMEOFFILE

// Add all files
git add --all
git add -a

Commit files

// Will bring up screen to write message
git commit

// Add message with shorthand command
git commit -m 'MESSAGE IN HERE'

Shorthand add and commit

git commit -a -m 'MESSAGE'

// Even shorter!!
git commit -am 'MESSAGE'

 

 Branching

Checkout

git checkout NAME/COMMIT/MASTER/BRANCH

Show changes between versions/branches

git diff IDENTIFIER IDENTIFIER 

Create branch / create & switch to branch

git branch BRANCHNAME

// Go straight to branch
git checkout -b BRANCHNAME

See all branches

git branch -a

// List remote branches
git branch -r

Delete branch

git branch -D BRANCHNAME

// Delete remote branch
git push origin --delete BRANCHNAME

 

Merging

Merging

git merge BRANCHNAME

Merge branch into master

git checkout BRANCHNAME
git pull origin master
git checkout master
git merge test

 

Remote repositories

Clone

git clone CLONENAME/PATH/URL

Add a new remote repository to the current repository

git remote add NAME

// Supplying URL
git remote add NAME URL

 

Pushing and Pulling

Push

git push origin NAME/MASTER

Pull

git pull origin NAME/MASTER

 

Extra cool stuff (Thanks, @earloftwirl)

Forget future changes (files with sensitive info, like config)

git update-index --assume-unchanged /path/to/file

Track changes again

git update-index --no-assume-unchanged /path/to/file

Remove a directory added by accident

git rm -r --cached FOLDERNAME

Move commits to a new branch

git branch newbranch
// Go back 3 commits. You *will* lose uncommitted work.
git reset --hard HEAD~3 
git checkout newbranch

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin
git reset --hard origin/master

Rebase from master

git fetch origin master	    # Updates origin/master
git rebase origin/master    # Rebases current branch onto origin/master

Tagging

git tag TAGNAME -am 'MESSAGE';
git push origin TAGNAME
// Or push all
git push --tags

// Tag a previous version
git checkout NAME/NUM
git tag TAGNAME
git push --tags
// Don't forget to go back to where you want to be e.g
git checkout master

// View tags
git tag -l

// Delete tag
git tag -d TAGNAME

Unstage changes before commit

git reset

See local unpushed commits

git log origin/master..HEAD

Worthy of Note

Worthy of Note is a site aimed at Web Designers & Developers. It offers a wide range of resources to help assist anyone in the web industry.

View