Thursday, November 19, 2009

Install git for Mac OS X Snow Leopard


mkdir ~/src
cd ~/src/
curl -O http://kernel.org/pub/software/scm/git/git-1.6.5.3.tar.bz2
tar -xjvf git-1.6.5.3.tar.bz2
cd git-1.6.5.3
./configure --prefix=/usr/local
make
sudo make install
git --version


This is how to create git-repo over ssh
suppose you have a project in ~/yourprojectdir
and the remote ssh server login is user@xxx.xxx.xxx.xxx
both client and server have git installed

Method 1

cd ~/yourprojectdir

git init

git add . # include everything below ./ in the first commit;
          # if you want to remove use git rm -r --cache xxx

git commit

cd ..

git clone --bare ~/yourprojectdir yourproject.git

touch yourproject.git/git-daemon-export-ok


then copy the git directory to your ssh sever

scp -r yourproject.git user@xxx.xxx.xxx.xx:/Volumes/HD/git/


setup git repo in ssh server

ssh user@xxx.xxx.xxx.xx "cd /Volumes/HD/git/yourproject.git; git --bare update-server-info; mv hooks/post-update.sample hooks/post-update"


check the location of remote git binary and the remote ssh login shell

ssh user@xxx.xxx.xxx.xxx "which git-upload-pack"
ssh user@xxx.xxx.xxx.xxx "echo \$PATH"

mine is /usr/local/bin/git-upload-pack


if the remote login shell does not include path of git, create ~/.bashrc in your remote ssh login shell

ssh user@xxx.xxx.xxx.xxx "echo 'export PATH=\${PATH}:/usr/local/bin' > ~/.bashrc"


push to remote git repo

cd ~/yourprojectdir

git remote add origin ssh://user@xxx.xxx.xxx.xxx/Volumes/HD/git/yourproject.git

git push origin master



Method 2

Create git repo in remote server

ssh user@xxx.xxx.xxx.xxx "mkdir -p /Volumes/HD/git/yourproject.git; cd /Volumes/HD/git/yourproject.git; git --bare init; touch git-daemon-export-ok"


Check the location of remote git binary and the remote ssh login shell as per Method 1

Commit project in your local and push to git repo

cd ~/yourprojectdir

git init

git add . # include everything below ./ in the first commit;
          # if you want to remove use git rm -r --cache xxx

git commit

git remote add origin ssh://user@xxx.xxx.xxx.xxx/Volumes/HD/git/yourproject.git

git push origin master



Test git clone

cd ~
git clone ssh://user@xxx.xxx.xxx.xxx/Volumes/HD/git/yourproject.git working
cd working
git log
git checkout


How to Branch

git branch -r # show branch in repo
git checkout -b todo origin/to-do-branch # checkout a new branch
git checkout master # checkout the master branch

git branch next # create new branch
git add .
git commit -m 'commit nextbranch'
git push origin next



How to fetch Branch from github repo

git clone git://github.com/username/repo-name.git
cd repo-name
git branch -r # show branch in repo
git checkout origin/to-do-branch # quick peek at an upstream branch
git checkout -b todo origin/to-do-branch # checkout a new tracking branch



To fetch a remote from github pull request # into your local repo

git fetch origin pull/<ID #>/head:NEWBRANCHNAME
git checkout NEWBRANCHNAME



Others
git config user.name "yourname"
git config user.email "your email"
git init .
git rebase -i
git commit --amend --author="Author Name "
git diff --stat
git diff --word-diff
git log --pretty='%h %d %s (%cr) [%an]' --graph --all
git config --global alias.lg "log --pretty='%Cred%h%Creset %C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)[%an]%Creset' --graph --all"




For subversion, it is here
http://subversion.apache.org/download/#recommended-release





2 comments:

Luke Hartman said...

Thanks for these. I'm wanting to setup a git repository on a Snow Leopard Server and this will come in quite handy.

yuetsu said...

this is nice, but how do you do this if your in 64-bit architecture? when i try to make using your example, it says it can't 'cuz the links are for i386, not 64-bit. please advise.