Back to Cheatsheets

git

Table of Contents

BASIC GIT WORKFLOW

BACKTRACKING

BRANCHING

TEAMWORK

BASIC GIT WORKFLOW

  1. Working directory: do all the work
  2. Staging area: list all changes
  3. Repository: where git stores the changes as versions

init

git init

status

git status

add

git add filename

diff

git diff filename

commit

git commit -m "message"

log

git log

BACKTRACKING

git show HEAD

Checkout

git checkout HEAD filename
OR
git checkout -- filename

Add two files

git add filename1 filename2

Reset

Single File

git reset HEAD filename

Different commit

git reset commit_SHA

BRANCHING

Check current

git branch

Create

git branch branch_name

Checkout

git checkout branch_name

Merge

git merge branch_name`

Merge Conflict

<<<<<< HEAD
master version of line
======
branch_name version of line
>>>>>> branch_name

Delete

git branch -d branch_name

TEAMWORK

clone

git clone remote_location clone_name

list remotes

git remote -v

fetch

git fetch

merge

git merge origin/master

workflow

  1. Fetch and merge changes from remote
  2. Create branch to work on mew project feature
  3. develop feature on branch and commit work
  4. fetch and merge from remote again (in case new commits)
  5. Push your branch up to the remote for review

push

git push origin branch_name