I learned something again today. Remember:
1: to create a git server repository, install git first.
1) install OpenSSH-server (SSH: Security shell );
Sudo apt-Get install OpenSSH-Server
2) create a warehouse directory and initialize the warehouse
Mkdri Server
CD Server
Git init
3) Add a file to the repository and submit it to the repository.
Mkdir Project
CD Project
Touch pro. Java
Git add pro. Java
Git commit pro. Java-m' file submission description '(the server does not need to push)
4) set the client to submit code
Open the. config file in the repository directory and add the following information:
[Receive]
Denycurrentbranch = ignore
------- End -----------
2. Client
1. Create a local repository file and clone the server Repository
Mkdir gitclient
CD gitclient
Git clone SSH: // username@127.0.0.1/home/username/Server localgit (local repository name, default and server name if not added)
In this step, the client reads files from the server (local git repository), creates a local repository, and creates a branch with the same name as the server. The default repository name is origin and the branch name is master.
------ End ------
Git obtains the latest version from a remote Branch to a local machine with the following two commands:
1. Git fetch: equivalent to obtaining the latest version from a remote device to the local device, without automatic merge
Git fetch origin master
Git log-P master... origin/Master
Git merge origin/Master
Meaning of the preceding command:
First, download the latest version from the master branch of the remote origin to the origin/Master branch.
Then compare the differences between the local master Branch and the origin/Master Branch
Merge at last
The above process can be implemented in the following clearer ways:
Git fetch origin master: TMP
Git diff TMP
Git merge TMP
Remotely obtain the latest version to the local test Branch
And then compare and merge
2. Git pull: equivalent to obtaining the latest version from a remote device and merge to the local device.
Git pull origin master
The above commands are actually equivalent to git fetch and git merge
In practice, git fetch is safer
Because before merge, we can check the updates and then decide whether to merge them.