Git for dummies

From FreekiWiki
Revision as of 20:49, 15 November 2008 by Ryan52 (talk | contribs) (reverting commits)
Jump to navigation Jump to search

The basics: What you need to know

Setup

Set up your system:

 sudo apt-get install git-core
 git config --global user.email somebody@somewhere.tld
 git config --global user.name "John Doe"

Note that if you are using debian etch, you will need to get a backport of git from backports.org.

Getting the repo

Get a copy of the library project (assuming the central repository is on a server named dev.freegeek.org):

 git clone dev.freegeek.org:/git/library
 cd library/

Sort of like svn update:

 git pull

Like svn update (but if you have local commits):

 git fetch
 git rebase origin/master

(Master is like trunk is in svn.)

Making changes

Now edit a file

 vi TODO 

(See it's just like svn!!)

Now schedule this modification to be committed locally:

 git add TODO 

Want to see changes that you hain't yet git added?

 git diff

Want to see what you are about to commit?

 git diff --cached

Now commit it locally:

 git commit

Now, if you want to commit all of the changes you've made, but don't want to "git add" a million files, you can shorted it to this:

 git commit -a

The -a tells git to commit "all"

If you screw up changes to a file, and just want to put it back:

 git checkout myfile

think of checkout (when used like this) as the git equivalent of "svn revert".

Now send your locally committed changes to the main repository:

 git push

Cool toys: What you want to know

also known as "candy for the coders".

cool settings

TODO

git-rebase -i

TODO

reverting a commit

yes, you can rebase out a commit. But never make changes to commits that have already been pushed. The correct way to "undo" a pushed commit is to run "git revert SHA1_HASH_GOES_HERE".

git-add -i

TODO

Complicated stuff: What you really don't want to know

Referencing a commit

TODO

Wtf is a refspec

TODO

Branches

TODO

Tags and all the associated evil

TODO

The index

So, with git you have multiple places where changes are "kept":

  • remote repository
  • local repository
  • the index
  • your working copy

The index is where you "stage" changes you are about to commit. git-add takes changes from your working copy and updates the index to match (this was called git-update-index in previous versions of git).

After you edit the file (in your working copy), there are a few steps to get it to the remote repository.

From working copy to index:

 git add file

From index to local repository:

 git commit

From local repository to remote repository:

 git push

Other junk

Git - SVN Crash Course