使用git进行版本控制--在多台PC上同步源代码

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

现在使用git来进行源代码管理,就轻松多了,而且还可以很方便地和别人一起协作开发。


步骤如下:

1. 配置server:

  mkdir repos.git
  cd repos.git
  git --bare init           # 建立一个空的 git仓库,--bare 参数说明当前init 的不是工作目录

2. 将PC-1上现有的workspace进行git管理并上传到服务器端:

  cd workspace
  git init
  git add *
  git commit -m 'initial commit'
  git remote add origin ssh://[email protected]/home/huzhenwei/repos.git            #192.168.1.2为服务器的VPN内网IP
  git push origin master        #将本地的代码上传到服务器端

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

  git clone ssh://[email protected]/home/huzhenwei/repos.git workspace
  cd workspace
  touch newfile         #创建一个新文件来做测试
  git add newfile
  git commit -m 'add newfile'
  git push origin master        #将本地的代码上传到服务器端

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

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

猜你喜欢

转载自blog.csdn.net/huzhenwei/article/details/7528923