Skip to content

Instantly share code, notes, and snippets.

@jclay
Last active December 24, 2015 01:09
Show Gist options
  • Save jclay/6721839 to your computer and use it in GitHub Desktop.
Save jclay/6721839 to your computer and use it in GitHub Desktop.
Git cheatsheet

Set username
git config --global user.name "Your Name Here"

Set e-mail
git config --global user.email "your_email@example.com"

Clorize and make git output pretty
git config --global color.ui true

Creating a repository
git init

Create a file

touch README.md
echo "Hello World" > README.md

Git status
git status
The file README.md we added above will show as untracked

Git add
Let's add our README.md to staging area
git add README.md

Git commit
Commit what we have in staging area to repository
git commit -m "Adding a README"

Git add remote origin
Add a remote so that we can sync our local repository
git remote add origin https://github.com/username/Hello-World.git

Create a new branch
git branch readme_update

Checkout (switch) to new branch
git checkout readme_update

A shortcut!
Create readme_update branch & checkout
git checkout -b readme_update

What branch are we on?
git status

Make some changes to readme

Add to staging area
git add README.md

Git status
Do our changes to README show up in staging area?
git status

Git commit
git commit -m "Committing changes to readme"

Switch back to master
git checkout master

Merge our changes from readme_update branch in
git merge readme_update

Delete readme_update branch
git branch -d readme_update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment