Skip to content

Instantly share code, notes, and snippets.

@irisli
Last active February 8, 2017 23:59
Show Gist options
  • Save irisli/9579127 to your computer and use it in GitHub Desktop.
Save irisli/9579127 to your computer and use it in GitHub Desktop.
Git cheatsheet
# Do this thing in order
# First, you should set up your ssh keys for github. If not, then you'll have to type a usenrame and password every time
# https://help.github.com/articles/generating-ssh-keys
# CD into where you want to store this project
# Adding the repository for the first time
# With ssh keys
git clone git@github.com:irisli/61b-network.git
# --- OR --- #
# Without ssh keys
git clone https://github.com/irisli/61b-network
# CD into 61b-network folder
cs 61b-network
# A. Uploading:
# 0. CHECK STATUS: You can see what files you have changed and what files need to be commited
git status
# 1. STAGING: Make changes to a file. Then you will have to STAGE the file. Do so by doing:
git add README.md
git add somefile.java
# 2. COMMITING: Once you have staged the file, now you are ready to COMMIT. This is still on your computer.
git commit -m "Meaningful comment"
# 3. PUSHING: Now, you have to PUSH your changes to the github server.
# pushing to origin head does magic since it will detect which branch you are currently on
git push origin head
# B. Fetching changes (Do whenever you start coding)
# 1. PULL: Pulling is the same thing as fetching and merging. Once you pull, then you update to the latest code as on github
git pull
# Fetch the changes
# git fetch
# Merge the changes. A merge tool thingy might show up. Scour the interwebs on how to merge stuff.
# git merge
# C. Checkout out existing branches
# 0. If branch doesn't exist, fetch the new branches
git fetch
# 1. Check out a branch
git checkout [branchname]
# D. Making your own branch
# 1. Start off on the branch that you want to branch off of (so if you want to make a branch
# that will get merged into master, you probably want to get the latest master and fork while still on the master branch)
git checkout master
git pull
# 2. Create a new local branch
git checkout -b [newbranchname]
# Make your changes (add, commits)
# 3. Push to remote
git push origin head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment