GIT

The Stupid Content Tracker

Author: David Montaño

Agenda

  • Description
  • Git Tutorial
  • Further Readings

Description

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Works with ssh or git protocol (git daemon listens on port 9418)

Git Tutorial

  • Importing a new Project
  • Making Changes
  • Git tracks Contents, not Files
  • Viewing Project History
  • Managing Branches
  • Using GIT for Collaboration
  • Exploring History
  • Git Daemon

Importing a new Project


$ tar xzf project.tar.gz
$ cd project
$ git init
						

$ git add .
						

$ git commit
						

Making Changes


$ git add file1 file2 file3
						

$ git diff --cached
						

$ git status
   On branch master
   Changes to be committed:
   Your branch is up-to-date with 'origin/master'.
     (use "git reset HEAD <file>..." to unstage)

           modified:   file1
           modified:   file2
           modified:   file3
						

$ git commit
						

$ git commit -a
						

Git tracks Contents, not Files

Many revision control systems provide an add command that tells the system to start tracking changes to a new file. Git’s add command does something simpler and more powerful: git add is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit.

Viewing Project History


$ git log
						

$ git log -p
						

$ git log --stat --summary
						

Managing Branches


$ git branch experimental
						

$ git branch

    experimental
    * master
						

$ git checkout experimental
# (edit file)
$ git commit -a
						

Managing Branches


$ git checkout master
# (edit file)
$ git commit -a
						

$ git merge experimental
$ git diff
# (resolve conflicts)
$ git commit -a
						

$ gitk
$ git branch -d experimental
$ git branch -D crazy-idea
						

Using GIT for Collaboration


bob$ git clone /home/alice/project myrepo
# (edit files)
bob$ git commit -a
# (repeat as necessary)
						

alice$ cd /home/alice/project
alice$ git pull /home/bob/myrepo master
						

alice$ git fetch /home/bob/myrepo master
alice$ git log -p HEAD..FETCH_HEAD
alice$ gitk HEAD..FETCH_HEAD
alice$ gitk HEAD...FETCH_HEAD
						

Using GIT for Collaboration


alice$ git remote add bob /home/bob/myrepo
alice$ git fetch bob
alice$ git log -p master..bob/master
alice$ git merge bob/master
alice$ git pull . remotes/bob/master
						

bob$ git pull
bob$ git config --get remote.origin.url
	/home/alice/project
bob$ git branch -r
	origin/master
bob$ git clone alice.org:/home/alice/project myrepo
						

Exploring History


$ git log
commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
Author: Junio C Hamano <junkio@cox.net>
Date:   Tue May 16 17:18:22 2006 -0700

   merge-base: Clarify the comments on post processing.
						

$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
$ git show c82a22c39c   # the first few characters of
			# the name are usually enough
$ git show HEAD         # the tip of the current branch
$ git show experimental # the tip of the "experimental" branch
						

Exploring History


$ git show HEAD^  # to see the parent of HEAD
$ git show HEAD^^ # to see the grandparent of HEAD
$ git show HEAD~4 # to see the great-great grandparent of HEAD
						

$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^)
$ git show HEAD^2 # show the second parent of HEAD
						

Exploring History


$ git tag v2.5 1b2e1d63ff
						

$ git diff v2.5 HEAD 	 # compare the current HEAD to v2.5
$ git branch stable v2.5 # start a new branch named "stable" based
			 # at v2.5
$ git reset --hard HEAD^ # reset your current branch and working
			 # directory to its state at HEAD^
						

Exploring History


$ git grep "hello" v2.5
$ git grep "hello"
						

$ git log v2.5..v2.6            # commits between v2.5 and v2.6
$ git log v2.5..                # commits since v2.5
$ git log --since="2 weeks ago" # commits from the last 2 weeks
$ git log v2.5.. Makefile       # commits since v2.5 which modify
                                # Makefile
						

Git Daemon


$ git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose
						

Further Reading

  1. man gittutorial
  2. man giteveryday
  3. man gitworkflows
  4. man gitcore-tutorial
  5. man gitcvs-migration
  6. Just one branch
  7. git flow
  8. learn git branching