Use git for version control - synchronize source code on multiple PCs

Because I often take my work home to do it, some codes written on my home computer are often too late to synchronize with the code on the company computer, leading to confusion in code management.

Now using git for source code management is much easier, and it is also very convenient to collaborate and develop with others.


Proceed as follows:

1. Configure the server:

  mkdir repos.git
  cd repos.git
  git --bare init #Create an empty git repository, the --bare parameter indicates that the current init is not the working directory

2. Git management of the existing workspace on PC-1 and upload to the server:

  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 is the VPN intranet IP of the server
  git push origin master #Upload the local code to the server

3. Check out the version library from the server to PC-2, create a new file on PC-2 and upload it to the server:

  git clone ssh://[email protected]/home/huzhenwei/repos.git workspace
  cd workspace
  touch newfile #Create a new file for testing
  git add newfile
  git commit -m'add newfile'
  git push origin master #local Upload the code to the server

4. Get the updated content of PC-2 on PC-1:

  git pull origin master #Download the server-side code to the local

Guess you like

Origin blog.csdn.net/huzhenwei/article/details/7528923