jschementi (owner)

Revisions

gist: 55621 Download_button fork
public
Description:
Git cheatsheets
Public Clone URL: git://gist.github.com/55621.git
Embed All Files: show embed
git-cheat.rdoc #

Add colors to your ~/.gitconfig file:

  [color]
    branch = auto
    diff = auto
    status = auto
  [color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
  [color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
  [color "status"]
    added = yellow
    changed = green
    untracked = cyan

Highlight whitespace in diffs

  [color]
    ui = true
  [core]
    whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol

Add aliases to your ~/.gitconfig file:

  [alias]
    st = status
    ci = commit
    br = branch
    co = checkout
    df = diff
    lg = log -p

Configuration

Sets your email for commit messages.

  git config user.email johndoe@example.com

Sets your name for commit messages.

  git config user.name 'John Doe'

Tells git-branch and git-checkout to setup new branches so that git-pull(1) will appropriately merge from that remote branch. Recommended. Without this, you will have to add —track to your branch command or manually merge remote tracking branches with "fetch" and then "merge".

  git config branch.autosetupmerge true

You can add "—global" after "git config" to any of these commands to make it apply to all git repos (writes to ~/.gitconfig).

Branching

Create local branch

  git branch search

Push local branch

  git push origin search

Delete local branch

  git branch -d search

Delete remote branch from remote repo (permanently)

  git push origin :search

Remove remote branch from local repo

  git branch -d -r origin/search

Rename local branch

  git branch -m search dev/search

Track a single remote branch as a local branch

  git checkout —track -b foo origin/foo

Pushing all local branches to remote, creating new remote branches as needed

  git push —all origin

Merging

Merge a branch into the current branch

  git merge foo

Remote

Create a "bare" git repo (just the contents of the .git folder) in the current directory

  git --bare init

Add a remote

  git remote add origin git@github.com:jschementi/foo.git

Rebase

Move all your commits in a "topic" branch to the top of the log

  git rebase master topic

Interactively rebase (reorder, combine, and delete commits)

  git rebase --interactive master topic

Tags

Create a tag at the current commit

  git tag -a this-is-a-tag

Push tags

  git push --tags