Create a Git code sharing repository server. 1. The server generally uses the SSH protocol. We should create a dedicated account for Git. $ Sudouseraddgit $ sudopasswdgitEnternewUNIXpassword: RetypenewUNIXpassword: passwd: passwordupdatedsuccessfully
Create a Git code sharing repository server.
1. Server
Generally, the SSH protocol is used. We should create a dedicated account for Git.
$ Sudo useradd git
$ Sudo passwd git
Enter new UNIX password:
Retype new UNIX password:
Passwd: password updated successfully
Create a directory for saving the code repository and grant the read and write permissions to the git account.
$ Sudo mkdir-p/var/git. server/project1
$ Cd/var/git. server
$ Sudo chown git project1
$ Sudo chgrp git project1
$ Ls-l
Total 4
Drwxr-xr-x 2 git 4096 2010-05-17 project1
Initialize project1. Note that you do not need to keep the working directory on the server. Therefore, create a pure (bare) code repository.
$ Cd project1/
$ Sudo su git
$ Pwd
/Var/git. server/project1
$ Git -- bare init
Initialized empty Git repository in/var/git. server/project1/
$ Ls-l
Total 32
Drwxr-xr-x 2 git 4096 2010-05-17 branches
-Rw-r -- 1 git 66 2010-05-17 00:59 config
-Rw-r -- 1 git 73 2010-05-17 00:59 description
-Rw-r -- 1 git 23 2010-05-17 00:59 HEAD
Drwxr-xr-x 2 git 4096 2010-05-17 hooks
Drwxr-xr-x 2 git 4096 2010-05-17 info
Drwxr-xr-x 4 git 4096 2010-05-17 objects
Drwxr-xr-x 4 git 4096 2010-05-17 refs
$ Exit
We cloned a copy on the server for Management and Testing (direct operations on the server repository directory should be prohibited ).
$ Git clone/var/git. server/project1/
Initialized empty Git repository in/home/yuyun/project1/. git/
Warning: You appear to have cloned an empty repository.
$ Ls-al project1
Total 12
Drwxr-xr-x 3 Yuanyuan YuanYi 4096 2010-05-17.
Drwxr-xr-x 10 Yuanyuan YuanYi 4096 2010-05-17 ..
Drwxr-xr-x 7 Yuanyuan yujia 4096 2010-05-17 0. git
We add the vertex project initialization file.
$ Cd project1
$ Cat>. gitingore <end
> *~
> *. Swp
> End
$ Touch README
$ Git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (Use "git add ... "To include in what will be committed)
#
#. Gitingore
# README
Nothing added to commit but untracked files present (use "git add" to track)
$ Git add.
$ Git commit-am "Start"
[Master (root-commit) 72100001e] Start
1 files changed, 2 insertions (+), 0 deletions (-)
Create mode 100644. gitingore
Create mode 100644 README
We submit the first version to the server.
$ Git push git @ localhost:/var/git. server/project1/master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 258 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
To git @ localhost:/var/git. server/project1/
* [New branch] master-> master
Generally, we can use origin to replace the server address. However, the current test account does not have the permission to write git. server/project1, so the ssh path is used. You must also specify branch.