首先安装Git,
在ubuntu下:
1 sudo apt-get install git
安装与设置ssh-key
1 $ ssh-keygen -t rsa 2 Generating public/private rsa key pair. 3 Enter file in which to save the key (/home/ray/.ssh/id_rsa): 4 Enter passphrase (empty for no passphrase): <输入key的密碼,或直接按下enter使用空密码> 5 Enter same passphrase again: <再输入一次密码> 6 Your identification has been saved in /home/ray/.ssh/id_rsa. 7 Your public key has been saved in /home/ray/.ssh/id_rsa.pub. 8 The key fingerprint is: 9 50:43:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 rayhome1987@gmail
其中id_rsa.pub是公钥,而id_rsa则是私钥,请妥善保存以免遺失,它们都存放于~/.ssh目录中。将公钥粘贴到你github帐号中的SSH Public Keys的位置。注意小心不要复制到空格。
然后在github上面注册一个账号
以下是新建一个repo的例子:
1 # Global setup: 2 3 # Download and install Git 4 git config --global user.email <your email=""> 5 git config --global user.name <your name=""> 6 7 # Next steps: 8 mkdir test # cd test 9 git init 10 # github会自动读取你的README内容并显示在项目简介中,因此先创建README 11 touch README 12 # 将README加到index中 13 git add README 14 # 提交到版本库中 15 git commit -m 'first commit' 16 # 把github的repo加入为远程的repo 17 git remote add origin git@github.com:<你的ID>/test.git 18 # 把目前的commit状态push并同步到github上面 19 git push origin master 20 21 # Existing Git Repo? 22 cd existing_git_repo 23 git remote add origin git@github.com:<你的ID>/test.git 24 git push origin master 25 </your></your>
克隆一个repo,通过以下命令:
1 git clone git@github.com:<id>/test.git test</id>
以下是git的一些日常操作:
1 # 创建一个版本库 2 git init 3 # 每次修改好了后,可以先将修改存入stage(快照/索引)中 4 git add <modified files=""> 5 # 修改了大量文件则使用下面这个命令批量存入 6 git add . 7 # 使用commit将快照/索引中的内容提交到版本库中 8 git commit -m "msg" 9 # 也可以将git add与git commit用一个指令完成 10 git commit -a -m "msg" 11 # 将本地的git档案与github(远程)上的同步 12 git push 13 # 将github(远程)的git档案与本地的同步(即更新本地端的repo) 14 git pull 15 # 例如,pull指令其实包含了fetch(將变更复制回來)以及merge(合并)操作 16 git pull git://github.com/tom/test.git 17 18 # 另外版本控制系統的branch功能也很有意思,若同时修改bug,又要加入新功能,可以fork出一个branch:一个专门修bug,一个专门加入新功能,等到稳定后再merge合并 19 git branch bug_fix # 建立branch,名为bug_fix 20 git checkout bug_fix # 切换到bug_fix 21 git checkout master #切换到主要的repo 22 git merge bug_fix #把bug_fix这个branch和现在的branch合并 23 24 # 若有remote的branch,想要查看并checkout 25 git branch -r # 查看远程branch 26 git checkout -b bug_fix_local bug_fix_remote #把本地端切换为远程的bug_fix_remote branch并命名为bug_fix_local 27 28 # 还有其它可以查看repo状态的工具 29 git log #可以查看每次commit的改变 30 git diff #可以查看最近一次改变的內容,加上参数可以看其它的改变并互相比较 31 git show #可以看某次的变更 32 33 # 若想知道目前工作树的状态,可以輸入 34 git status 35 </modified>
本篇文章属于转载,地址为:http://www.cnblogs.com/singleboss/archive/2012/05/08/2489669.html ,作者若有异议,请联系本人,本人会尽快删本篇文章!谢谢!

浙公网安备 33010602011771号