Skip to content

Instantly share code, notes, and snippets.

@richardcornish
Last active December 4, 2025 03:24
Show Gist options
  • Select an option

  • Save richardcornish/4676556 to your computer and use it in GitHub Desktop.

Select an option

Save richardcornish/4676556 to your computer and use it in GitHub Desktop.
Enough Git for your résumé in 100ish lines

Git notes

Start

  1. Install Git
  2. Create a GitHub account
  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

Create the remote repository at GitHub as My Project.

Create the local repository.

mkdir -p ~/Code/myproject/ && cd ~/Code/myproject/
git init
echo "# My Project" > README.md
git add README.md  # Or `git add .` for adding all
git commit -m "First commit"
git remote add origin git@github.com:myusername/My-Project.git
git push -u origin master  # subsequently `git push`

Go to https://github.com/myusername/My-Project (or refresh page).

Ignore stuff

echo "*.DS_Store" > .gitignore
git add .gitignore
git commit -m "Added ignore file"

Get a repository

git clone git@github.com:theirusername/Their-Project.git`

Update a repository

git pull origin master

Feature branches

Add new feature branch:

git checkout -b my-new-feature-branch  # `-b` is shortcut for creating and switching to new branch
# work on new feature
git status
git add new-file.html
git rm worthless-file.html
git commit -m "First edit for the feature"
# work some more
git add more.min.js
git diff --staged
git commit -m "Second edit for the feature"
# You could push my-new-feature-branch out to remote if collaborating with others
# git push origin my-new-feature-branch

Update with new feature branch:

git checkout master
git pull origin master
git merge someone-elses-new-feature-branch
git push origin master

If master is ahead of you:

# You could `git pull && git push`...but "merge commits" are ugly
git fetch  # you should be on master
git checkout my-new-feature-branch
git rebase master
git checkout master
git merge my-new-feature-branch

If you have conflicts:

git fetch  # you should be on master
git rebase
# fix conflicts
git add broken_file.html
git rebase --continue

Delete new feature branch:

git checkout master
git branch -d my-new-feature-branch
git push origin --delete my-new-feature-branch  # deletes remote branch
git remote prune origin  # deletes remote branch more

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

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

  • 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

@coden-nbaa

Copy link
Copy Markdown

Double plus good.

@rashthedude

Copy link
Copy Markdown

+1

@Akhi1

Akhi1 commented May 20, 2015

Copy link
Copy Markdown

that's pretty handy....thanks!

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