HOWTOlabs  
 Services     Software     Commentary     Design     Astral Musings   
git
tips and best practices

Elsewhere

[edit]

git

git is a 'peer-to-peer' style source code management application developed originally by Linus (creator of Linux) to better manage Linux kernel development.  It has been enhanced and ported to various computer operating systems including Linux, OS X, and Microsoft Windows.

It differs from traditional source code management systems in that is eschews the client/server model, instead allowing multiple peer code repositories to exists and interact with each other organically as needed.  This provides increased flexibility, but also increases the conceptual complexity of managing code that now can evolve in many repositories simultaneously.

Getting git: Apple OS X

As of at least OS X 10.4, use the disk image installer.

Often terminal path does not include location of git commands.  As root, it doesn't hurt to add git path as default for standard logins.

$ cat /etc/rc.common | grep PATH

  PATH=/bin:/sbin:/.../CoreServices:/usr/local/git/bin; export PATH 

If OS X needs to accept remote git requests (i.e. server mode), each user account making requests may need path settings tweaked to include git commands.  This needs to be done only on the server-side.

$ cd ~

$ cat .bashrc

  export PATH=$PATH:/usr/local/git/bin 

Getting git: Linux RedHat/Centos

$ cd ~

# yum list \*git\*

  git.x86_64

# yum install git

  Downloading Packages:
  (1/3): git-1.7.1-2.el6_0.1.x86_64.rpm
  (2/3): perl-Error-0.17015-4.el6.noarch.rpm
  (3/3): perl-Git-1.7.1-2.el6_0.1.noarch.rpm                              |  

# exit

$ cd ~/test-git/test 

Using git: managing local files

$ cd /public/test-git

$ cd test

$ git status -s

  fatal: Not a git repository (or any of the parent directories): .git

$ vi hello.txt

$ git init

  Initialized empty Git repository in .../test-git/test/.git/

$ git status -s

  ?? hello.txt

$ git add hello.txt 

$ git status -s

  A_ hello.txt

$ git commit

  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 hello.txt

$ git status -s 

Using git: cloning files

$ cd /public/test-git$ cd ~/test-git

$ git clone /public/test-git/test

  Cloning into test...
  done.

$ cd test

$ git status -s 

Using git: undoing changes

$ vi hello.txt

$ git add

[ perform a bogus edit ]

$ git status -s

  _M hello.txt

$ git reset HEAD -- hello.txt

$ git status -s

$ rm hello.txt

$ git status -s 

  _D hello.txt

$ git checkout -- hello.txt

$ git status -s 

Remote Clone

Cloning from a remote location will automatically add remote alias.  Prepend username@ to hostname if remote is different.

$ git clone test.zaptech.org:/public/test-git/basic

  Cloning into basic...
  username@git.mydomain.com's password: 
  Receiving objects: 100% (3/3), done.

$ git remote -v

  origin git.mydomain.com:/public/test-git/basic (fetch)
  origin git.mydomain.com:/public/test-git/basic (push)

[ create a new file ]

$ git add

$ git commit

$ git diff origin --shortstat

  1 files changed, 1 insertions(+), 0 deletions(-) 

Remote Branches

$ git branch

  [ show branches and which one is current ]

$ git branch --track exp origin

  Branch exp set up to track remote branch master from origin.

$ get checkout exp

  [ switch to exp branch ]

$ git branch

  [ show branches and which one is current ] 

Client/Server Setup

Clone, prepare - for server only
$ git clone --bare b2 b0 
Clone, checkout, commit, push - for client
$ git clone test.zaptech.org:/public/test-git/basic

  [ change some files ]

$ git add

$ git commit -m "comment"

$ git push 

Remote Merging

$ git fetch origin

  From test.zaptech.org:/public/test-git/basic
  ... master -> origin/master

$ git diff origin/master

  @@ -1,2 +1,2 @@
  -update 2012-01-13
  +test
 
$ git merge origin/master

  Fast-forward
  notes.txt |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

$ vi notes.txt 

  [ change notes.txt ]

$ git status -s

   M notes.txt

$ git add notes.txt 

$ git commit notes.txt -m "second tweak"

  1 files changed, 1 insertions(+), 1 deletions(-)

$ git status -s

$ git push origin

  Total 3 (delta 1), reused 0 (delta 0)

  ...  master -> master 

[edit]

zap technologies
printable