Saturday, December 29, 2012

Install Git and GitHub for snow leopard

I have a snow leopard laptop. 

From http://git-scm.com/download/mac, it automatically downloaded  "git-1.8.0.2-3-intel-universal-snow-leopard.dmg". Double-click this file generated a "Git 1.8.0.2 Snow Leopard Intel Universal" disk, which contains four files: 1) uninstall.sh, 2) README, 3) 'setup git PATH for non-terminal programs.sh, 4) git-1.8.0.2-intel-universal-snow-leopard.pkg. After running the fourth file, a successful install message occurred. 

I then found out that the free GUI for Git, GitHub, has stopped support for snow leopard. This leaves me the only option to follow the command-line version on https://help.github.com/articles/set-up-git.

$ git config --global user.name "hongqin"
$ git config --global user.email "myworkemail@gmail.com"
$ curl -s -O \
  http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
$ chmod u+x git-credential-osxkeychain 
$ cd /opt/local/bin   #I saw osxkeychain already here
$ git config --global credential.helper osxkeychain

By now, I have finished all the steps on https://help.github.com/articles/set-up-git.  

I then proceed to created a 'Public' repository, named "sandbox". I chose a README option.  After hitting the green "create repository" button, a new page appeared in about one second.

When I clicked "Clone in Mac", it took me back to GitHub Mac version for 10.7+. When I clicked "ZIP", it started download "sandbox-master.zip" into local Download. This zip file contains the README.md file and the sandbox-master directory structure.  I then noticed that I was in the 'branch:master' mode. 

To test how GitHub works locally, I created a hello world file in local sandbox-master. 



$cd sandbox-master
$git init
Initialized empty Git repository in /Users/hongqin/github/sandbox-master/.git/

$ git add helloworld.txt
$ git commit -m "first local commit"
[master (root-commit) 6654d46] first local commit
 1 file changed, 1 insertion(+)
 create mode 100644 helloword.txt


$ git remote add origin https://github.com/hongqin/sandbox.git
$ git push origin master
Username for 'https://github.com': hongqin
Password for 'https://hongqin@github.com':
To https://github.com/hongqin/sandbox.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/hongqin/sandbox.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


This non-fast-forward error seems to be a common error:
https://help.github.com/articles/dealing-with-non-fast-forward-errors

$ git push --force origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 230 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/hongqin/sandbox.git
 + c8d6cad...6654d46 master -> master (forced update)


I then refreshed GitHub sandbox web page, and found "helloworld.txt" there. But "README.md" disappeared.This may explain my 'non-fast-forward error'.

$ git add README.txt
$ git commit -m "second local commit"

[master bdcefa8] second local commit
 1 file changed, 2 insertions(+)
 create mode 100644 README.txt
 

$ git remote add origin https://github.com/hongqin/sandbox.git
fatal: remote origin already exists.
 
$ git push origin master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 288 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/hongqin/sandbox.git
   6654d46..bdcefa8  master -> master
 
I  then refreshed my GitHub webpage and see both files. 

Oddly, there is still "README.md" file, but I do not see this file in the downloaed ZIP archive.  I leave it for now. 
 

No comments:

Post a Comment