Sunday, November 22, 2009

How to create local and remote ssh git repo in Mac OS X

(1) Install git for Mac OS X

mkdir ~/src
cd ~/src/
curl -O
tar -xjvf git-
cd git-
./configure --prefix=/usr/local
sudo make install
git --version

(2) Suppose you have a project in ~/myproject
and the remote ssh server login is
both client and server have git installed

(3) Create localrepo in local harddisk

git mkdir -p ~/git
git clone --bare ~/myproject ~/git/myproject.git
touch ~/git/myproject.git/git-daemon-export-ok

push to localrepo

cd ~/myproject
git init
git add .
git rm -r --cache build     # ignore the build directory for iPhone project
git commit -m 'Initial commit'
git remote add localrepo ~/git/myproject.git
git push localrepo master
git log

(3) Create sshrepo in remote server over ssh

ssh "mkdir -p /Volumes/HD/git/myproject.git; cd /Volumes/HD/git/myproject.git; git --bare init; touch git-daemon-export-ok"

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

ssh "which git-upload-pack"
ssh "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 "echo 'export PATH=\${PATH}:/usr/local/bin' > ~/.bashrc"

push to sshrepo

cd ~/myproject
git remote add sshrepo ssh://
git push sshrepo master
git log

Test git clone

cd ~
git clone ~/git/myproject.git workinglocal
cd workinglocal
git log


cd ~
git clone ssh:// workingremote
cd workingremote
git log

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 checkout localrepo/master # checkout the master branch in localrepo
git checkout sshrepo/master   # checkout the master branch in sshrepo

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

git branch -b cygwin
git branch -r
git add *
git commit -m 'commit cygwin branch'
git push origin cygwin

How to checkout a previous commit

git log # show log of previous commit
git log --format=oneline # show log of previous commit log hex digit
git checkout 838fbf2e9b050d2350694235bbf5e9a11fa7acea # commit log hexdigit

How to push to github

git config --global "javacom"
git config --global ""
git remote rm origin
git remote add origin
git push origin master

No comments: