Skip to content

Instantly share code, notes, and snippets.

@agustibr
Forked from richardcornish/git.md
Created April 14, 2016 13:01
Show Gist options
  • Save agustibr/d639f46d0f207d052a419966e4edf035 to your computer and use it in GitHub Desktop.
Save agustibr/d639f46d0f207d052a419966e4edf035 to your computer and use it in GitHub Desktop.
Enough Git for your résumé in 100ish lines
Start
=====
1. Install Git
http://git-scm.com/download/mac
(But consider using Homebrew)
2. Make a GitHub account
https://github.com/
3. Open Terminal
/Applications/Utilities/Terminal.app
Configure
=========
git config --global user.name "Your Name"
git config --global user.email "you@email.com"
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" > README.md
git add . # Shortcut for adding all, which is just README.md
git commit -m "My first commit. So precious."
git remote add origin git@github.com:yourusername/Totes-Awesome-Project.git
# Create the new repository at https://github.com/new as "Totes Awesome Project"
git push -u origin master # subsequent times, git push
# Go to https://github.com/yourusername/Totes-Awesome-Project
Get a repository
================
git clone https://github.com...
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 pull origin 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 --delete this-is-my-new-feature-branch # deletes remote branch
git remote prune origin # deletes remote branch more
Stay updated with others
========================
cd totes-awesome-project
git pull origin master
Tags
====
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!
Confused?
=========
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 https://github.com/yourusername/cool-forked-project.git
cd cool-forked-project
git remote add upstream https://github.com/theotherguy/cool-forked-project.git
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 manage.py 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:
- http://firstaidgit.io/
- https://help.github.com/articles/create-a-repo
- http://rogerdudler.github.com/git-guide/
- http://hoth.entp.com/output/git_for_designers.html
- http://gitimmersion.com/
- http://csswizardry.com/2012/12/my-git-workflow-for-inuit-css/
- http://mac.github.com/
- http://git-scm.com/doc
- https://delicious.com/richiesee/git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment