[Home]Git

ec2-18-216-123-120.us-east-2.compute.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic

Git is the "cool kids'" source control system, but I keep forgetting how to use it.

Man pages


Open top-level help page
       git help

Open man page for specific command
       git help <command>

Create a new, empty repository


Git works entirely locally, you can get started in any directory at any time by simply typing:
       git init

Pull a remote git repository


Switch to an empty directory, and initialize git with the remote URL (this example is Linus' Linux main branch):
       git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Basic add and remove


Track files for submission:
       git add <files>
      git add -u .            [All modified (but not new) files]
      git add -A .            [All files]

Track files for deletion:
       git rm <files>

Stop tracking files:
       git reset

Commit changes to repository:
       git commit

Commit to repository all tracked changed files, and all new files that have been added:
       git commit -a

Commit changes to repository with specified message
       git commit -m"This implements the whizzy thing"

Current state of your working directory


View files that do not match the current repository master:
       git status

Perform diff against repository master (note the diff default to changes since your last git add)
       git diff <files>

Viewing commit history


View previous committed changes:
       git log
      git log -- <files>

Switch to a different historical version of the tree/master
       git checkout [changeId] -- <files>
      git checkout master
      git checkout .                  [Abandons any untracked changes]

Throw away your current local changes:
       git checkout -f HEAD

Revert a commited change
       git revert

Bisect a problem
       git bisect start
      git bisect [good|bad] version    [Verson that is ok or exhibits the problem]

       For each step:
      git bisect [good|bad]            [Current version is ok/exhibits problem]

       When complete:
      git bisect reset

Branching


Creating and switching between branches:
       git branch                       [show branches]
      git branch <name>                [create branch]
      git checkout <name>              [switch to branch]
      git branch -d <name>            [delete branch]

Merging changes between branches
       git merge <otherbranch>          [pull all changes from otherbranch]
      git cherry-pick <commit>        [pull a list of commits by their unique id]

Temporary branches
       git stash save                   [temporary commit and revert to HEAD]
      git stash save -u                [similarly but also include new files]
      git stash pop                    [retrieve saved state]

ec2-18-216-123-120.us-east-2.compute.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic
This page is read-only | View other revisions | Recently used referrers
Last edited September 8, 2014 12:41 pm (viewing revision 6, which is the newest) (diff)
Search: