breno.leitao@gmail.com Linux Technology Center May 16, 2008
Agenda Introduction Concepts Commands (Tutorial) Front Ends
History Started in 2005 to replace BitKeeper. Designed to support the kernel development. Used widely: Wine, Beryl, OLPC, Fedora, Ruby on Rails, VLC, yum, etc Multi-platform: Mac OS X, Windows, Linux and Unix GPL v2 Originally written by Linus Torvalds Git is currently maintained by Junio C Hamano
The name "I m an egotistical bastard, and I name all my projects after myself. First Linux, now git 1 " Linus Torvald 1 git is British slang for silly, stupid, or worthless person
The name Alternatively, Linus said: that git can mean anything, depending on your mood: Random three-letter combination that is pronounceable, and not actually used by any common UNIX command. Stupid. Contemptible and despicable. Simple. Global information tracker and it actually works for you. if you re in a good mood, Goddamn idiotic truckload of sh*t when it breaks
Linus core goals It must be distributed Disconnected mode of operation Trusted Lieutenants concept Very strong safeguards against corruption, either accidental or malicious Fast merge and search "Take CVS as an example of what not to do; if in doubt, make the exact opposite decision." Linus
What is git Git manages changes to tree of files over time. Git is optimized for: Distributed Development Large files set Complex merges Making trial branches Being very fast Being robust Git is not optimized for: Tracking file permissions and ownership Track individual files with separate history
Usage Concepts Everyone has the commit bit. Send the patch or publish repository. Multiprotocols: git, HTTP and SSH. Everyone has the entire repository. (Disks are cheap) Every ID is based on SHA-1 2 2 160 bits long
Design git is divided in two kind of commands: Porcelain These are high-level commands Used mainly by humans Commands subject to change in order to improve the end user experience. Plumbing Low level commands Used mainly by scripts. Commands are more stable
Facts The overall design is heavily based on pipeline of tools UNIX philosophy. Mostly written in C, with higher level UI in POSIX shell and some Perl/Python/Wish mixture. Every git command is a git-xxxx application 3. Currently more than 130 commands are available. Git doesn t have a specialized built-in help system. Getting Documentation man git-foo git help foo git foo --help 3 git-clone, git-push, git-diff
Concepts Repository Working tree Branch Master repository Tag Head Merge Index 4 4 A concept that appeared in git
Repository A repository is an archive of what the working tree looked like at different times in the past whether on your machine or someone else s.
Working tree The tree of actual checked out files. The working tree is normally equal to the HEAD plus any local changes that you have made but not yet committed. Contains a.git directory.
The.git/config file [core] repositoryformatversion = 0 logallrefupdates = true [remote "origin"] url = ssh://brenohl@speck.ltc.austin.ibm.com/git/fvt/networ fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [gui] geometry = 1399x943+0+25 347 263 [user] name = Breno Leit~ao email = leitao@linux.vnet.ibm.com
Branch A branch starts a new development tree, which is disjoint from the other you ve just cloned.
Branch No single repository is inherently authoritative. Linus s repository is official only by social convention. Everybody can fork and make his own changes. Typically, a branch is used to work on a specific topic.
Master The mainline of development in most repositories is done on a branch master called master. Although this is a typical default, it is in no way special.
Tag A tag is a link to a commit ID. A tag object contains an object, object type, tag name, the name of the person ( tagger ) who created the tag, and a message, which may contain a signature, as can be seen using the git-cat-file.
HEAD The word HEAD refers to the most recent commit of the last branch you checked out. Thus, if you are currently on the master branch, the words master and HEAD would be equivalent. HEAD refers to the previous commit HEAD 2 refers to two commits back in the history.
Merge Consolidate work git uses the 3-way merge algorithm if only one-side changes, take that change. if both sides change to the same result, use it. otherwise it is a conflict. Also applied to paths We currently do merges faster than anybody else
Branches, merges and collision
Index Unlike other, similar tools you may have used, Git does not commit changes directly from the working tree into the repository. Instead, changes are first registered in something called the index. Some find it helpful to call it instead as the staging area, instead of the index.
Flow
Creating the Repo git-init creates the repository. breno@cafe:~/git# git init Initialized empty Git repository in.git/
Adding a file git-add adds a file in the repository or mark it to be considered during the commit breno@cafe:~/git# echo Hello World > hello.txt breno@cafe:~/git# git add hello.txt
Committing git-commit commit the changes you did and added breno@cafe:~/git# git commit -m "My first commit" Created initial commit d4baed6: My first commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hello.txt
Historical changes git-log shows the historical modification in a branch Also supports advance arguments as git log --since="2 weeks ago" --until="yesterday" # git log commit 32ade9636de5eed401fa8c819cc317f4fa795699 Author: Breno Leitao <breno@cafe.(none)> Date: Mon May 12 22:38:17 2008-0300 My second commit commit d4baed65b47fb848f92d814ed149c62d62ca427d Author: Breno Leitao <breno@cafe.(none)> Date: Mon May 12 22:34:37 2008-0300 My first commit
Detailed changes git-show dumps one specific modification, and the patch that provoked the change # git show 32ade9636de5eed401fa8c819cc317f4fa795699 commit 32ade9636de5eed401fa8c819cc317f4fa795699 Author: Breno Leitao <breno@cafe.(none)> Date: Mon May 12 22:38:17 2008-0300 My second commit diff --git a/hello.txt b/hello.txt index 557db03..d3636ff 100644 --- a/hello.txt +++ b/hello.txt @@ -1 +1 @@ -Hello World +Hello World version 2
Differences before committing git-diff shows the diff between the working tree and the repository. # git diff diff --git a/hello.txt b/hello.txt index d3636ff..6913f91 100644 --- a/hello.txt +++ b/hello.txt @@ -1 +1 @@ -Hello World version 2 +Hello World version 3
Git branch git-branch creates, deletes and list branches. breno@cafe:~/git$ git branch newfeature breno@cafe:~/git$ git branch * master newfeature
Git checkout git-checkout checks out a branch breno@cafe:~/git$ git checkout newfeature M hello.txt Switched to branch "newfeature" breno@cafe:~/git$ git branch master * newfeature
Merging branches breno@cafe:~/git$ git checkout master Switched to branch "master" breno@cafe:~/git$ cat hello.txt Hello World version 3 A new line in a new branch Done in master breno@cafe:~/git$ git checkout newfeature Switched to branch "newfeature" breno@cafe:~/git$ cat hello.txt Hello World version 2 breno@cafe:~/git$ git merge master Updating 32ade96..a218c02 Fast forward hello.txt 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) breno@cafe:~/git$ cat hello.txt Hello World version 3 A new line in a new branch Done in master @cafe:~/git$ git branch -d master Deleted branch master.
Front Ends gitk, gitview gitweb tig
Gitk
Git-gui
Git web
tig
END Thank you!