Git Cheatsheet

Written by Supakorn Laohasongkram on September 8rd, 2014

Connecting your Local Git to Your GitHub Repository

  • Go to GitHub. Create an account and set up a new repo.
  • Copy the repo 'http'
  • Go to Terminal
  • Navigate to the folder where you want to link your repo
  • Type the following code follow by the specific http of your repo.
  • 								git clone 'http'

    Checking/Creating/Changing/Deleting Branch

  • List all existing branches
  • 								git branch 
  • Creating new branch
  • 								git branch -b 'branch'
  • Switch to the designated branch
  • 								git checkout 'branch'
  • Deleting a branch
  • git push origin --delete 'branch'

    Staging/Committing/Pushing Files

  • Checking Current Status
  • 								git status
  • Staging All Files
  • 								git add -A
  • Commiting Staged Files
  • 								git commit -m "comment"

  • Pushing/Uploading Files from local hard drive to GitHub
  • 								git push 'remote' 'branch'

    Setting Up New Remote for Your Local Repo

  • Checking Current Remotes
  • 								git remote -v
  • Adding new upstream
  • git remote add upstream 'http'

    Fetching Files from GitHub to Your Local Repo

  • Fetch files from Upstream
  • 								git fetch upstream
  • Merging files from Upstream to branch
  • 								git merge upstream/'branch'
  • Fetch and Merge files
  • 								git pull 'remote'

    Dealing with Conflicts

  • Display unstaged changes
  • 								git diff
  • Display changes compare to a specific branch or commit
  • 								git diff 'commit/branch'

    * you actually make the changes in your text editor


    © Copyright Supakorn Laohasongkram 2014