Skip to content

Instantly share code, notes, and snippets.

@jshawl jshawl/git-notes forked from richardcornish/Git notes
Last active Aug 29, 2015

What would you like to do?
1. Install Git
(But consider using Homebrew)
2. Make a GitHub account
3. Open Terminal
git config --global "Your Name"
git config --global ""
git config --global color.ui true
git config --list
Create a repository
mkdir -p ~/Desktop/totes-awesome-project/
cd ~/Desktop/totes-awesome-project/
git init
echo "# Totes Awesome Project" >
git add . # Shortcut for adding all, which is just
git commit -m "My first commit. So precious."
git remote add origin
# Create the new repository at as "Totes Awesome Project"
git push -u origin master # subsequent times, git push
# Go to
Get a repository
git clone
Work on a new feature
git checkout -b this-is-my-new-feature-branch # -b is shortcut for creating and switching to new branch
subl . # Sublime specific, so just work on something
git status
git add html9-boilerplate-framework-omg.css
git rm worthless.html
git commit -m "First edit for the feature"
# Work some more
git add whatever.min.js
git diff --staged
git commit -m "Second edit for the feature"
# You could push this-is-my-new-feature-branch out to remote if collaborating with others
# git push origin this-is-my-new-feature-branch
Update with new feature branch
git checkout master
git merge this-is-my-new-feature-branch
git push origin master
(If master is ahead of you)
# You could git pull && git push ...ehhh "merge commits" are ugly
git fetch # you should be on master
git checkout this-is-my-new-feature-branch
git rebase master
git checkout master
git merge this-is-my-new-feature-branch
(If you have conflicts)
git fetch # you should be on master
git rebase
# Fix conflict
git add broken_file.html
git rebase --continue
Delete new feature branch
git checkout master
git branch -d this-is-my-new-feature-branch
git push origin :old_branch # deletes remote branch
git remote prune origin # deletes remote branch more
Stay updated with others
cd totes-awesome-project
git pull origin master
git tag # list tags
git tag -a v0.0.2 -m "Version 0.0.2" # add new tag
git push --tags # push new tags
git checkout v0.0.1 # checkout tag
Ignore stuff
touch .gitignore
echo *.DS_Store > .gitignore
git add .gitignore
git commit -m "Edit ignore file"
Undo mistakes
git reset --soft HEAD^ # Undoes last commit, files are back to staged
git reset --hard HEAD^ # Undoes last commit, and undoes the edits of those files! Nuclear option!
git status # Show (un)tracked/(un)staged files
git branch # Show branches and which one you're on
git branch -r # List all remote branches
git remote show origin # Show all remote branches
git log # Show the commits, or git log --graph for pretty
git show thelonggitlognumber1234567890 # Show old versions of files
git diff # Show diff between tracked and last commit
git diff thelonggitlognumber1234567890 # Show diffs between file versions
git blame file.html # Show author of change
Fork someone's work
# Go to GitHub project, click Fork
git clone
cd cool-forked-project
git remote add upstream
git fetch upstream
git merge upstream/master
# Visit your repo webpage to send pull request
Benefits of Git:
- You have a local copy of the repository, which complements local development with `rails s`/`python runserver`
- Branching for new features is easier than SVN
- Faster/smaller in size than SVN
- Just remember to visualize the local/remote + branch/master way of thinking
Good links:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.