首页 > 技术文章 > git代码版本管理

Amagasaki 2014-03-24 10:24 原文

 1.  Set Up Git

$ git config --global user.name "Your Name Here"
$ git config --global user.email "your_email@example.com"
$ git config --global credential.helper cache  # timeout=900 by default
$ git config --global credential.helper 'cache --timeout=3600'

 2. Create A Repo

  •   Make a new repository on GitHub

     Click New Repository

  •   Create a README for your repository

     Step 1: Create the README file      

$ mkdir ~/Hello-World
$ cd ~/Hello-World
$ git init
$ touch README

       Step 2: Commit your README

$ git add README
$ git commit -m 'first commit(your description)'      
# git add <filename>
# git add <folder>
# git add -u # 只加修改过的文件,不加入新增文件
# git add -i # 进入交互模式i

# git rm <filename>
# git mv <filename> <newfilename>
# git mv <folder> <newfolder>

       Step 3: Push your commit

$ git remote add origin https://github.com/username/Hello-World.git
$ git push origin master

 附:

error: RPC failed; result=56, HTTP code = 0
refer here
$ git config http.postBuffer 524288000 

 参考:

官网:https://help.github.com/articles/set-up-git

其他链接:http://rogerdudler.github.io/git-guide/index.zh.html    

 

因为经常把工作带回家去做,在家用电脑上写的一些代码常常来不及与公司电脑上的代码进行同步,导致代码管理混乱。

现在使用git来进行源代码管理,就轻松多了,而且还可以很方便地和别人一起协作开发。
1. 将PC-1上现有的Hello-World进行git管理并上传到服务器端:

  cd ~/Hello-World
  git init
  git add *
  git commit -m 'initial commit'
  git remote add origin https://github.com/username/Hello-World.git          
  git push origin master        #将本地的代码上传到服务器端

2. 从服务器端检出版本库到PC-2,在PC-2上新建文件并上传到服务器端:

  git clonehttps://github.com/username/Hello-World.git Hello-World
  cd Hello-World

i) add new file
  touch newfile         #创建一个新文件来做测试
  git add newfile
  git commit -m 'add newfile'
  git push origin master        #将本地的代码上传到服务器端

ii) modify file

 # modify the files, then

 git checkout

 git add <file>

 git commit -m 'modify the file'

 git push origin master

3.在PC-1上获取PC-2更新的内容:

  git pull origin master        #将服务器端的代码下载到本地  

推荐阅读