1. Install Openssh-server to create the SSH service.
sudo apt-get install Openssl-server
Use the command ps-e|grep SSH to see if the SSH service is started.
If it starts normally, a similar message appears: 1966? 00:00:00 ssh-agent
2. Create a user named Git to manage and run the Git service.
sudo user del-r git///Add user named Git;
Enter the git user directory, create a directory. SSH, and then create a file named Authorized_keys in the. SSH directory;
cd/home/gitsudo mkdir. sshcd. Sshtouch Authorized_keys
Copy the client's public key (generated as described below) to the Authorized_keys file;
Cat Path/id_rsa.pub >>/home/git/.ssh/authorized_keys
Installing Git-core
sudo apt-get install Git-core
3. Initializing the service-side warehouse
Git-bare Init/home/git/test1.git
Note: This command generates an empty warehouse, at which point the test1.git address is [email protected]:/home/git/test1.git
Or:
mkdir TEST1.GITCD test1.gitgit-bare Init
4. The client runs ssh-keygen-t RSA generated key;
After generating the key, in the. SSH directory, there will be two files Id_rsa and id_rsa.pub files, id_rsa.pub for the public key, through the command scp/home/git/.ssh/id_rsa.pub gitserver:/home/ Git copies the public key generated on the client to the Gitserver;
After the server adds the public key to the Authorized_keys file, the client can access the GIT repository through the path;
When the key is generated, you are asked to confirm the location where the public key is saved (by default, ~/.ssh/id_rsa), and then let the password be repeated two times, if you do not want to enter the password when using the public key, leave blank;
Assume that HostIP is 192.168.1.100
git clone [email protected]:/home/git/test1.git
5. Common git commands
>1. git clone
Syntax: Git clone repository URL local library name (can be omitted)
>2. Git remote
This command is used to manage remote host names, and all hostnames can be listed without parameters;
Git remote origin
Show Origin is when you clone a remote repository using the clone command, GIT automatically commands the remote host;
See the repository address via Git remote-v;
>3. git fetch
Syntax: Git fetch origin (Git fetch Origin master)
By default, GIT fetch origin will update all branches on origin of the remote host, and if you want to update only one branch, add the branch name after the host name
>4. git push
Syntax: git push remote host name local branch name: remote Branch Name
If the remote branch name is omitted, the local branch is pushed to the remote branch that has the final relationship, and if the remote branch does not exist, it is created;
Git push origin master, which means that the local master branch is pushed to the master branch of the origin host;
If you omit the local branch name, it means that you want to remove the branch from the remote host, such as Git push origin:master, to delete the master branch from the origin host;
>5. Git pull
Syntax: GIT pull remote host remote branch: local branch such as: Git pulling origin master:master, means to update the Master branch in origin of the remote host to the local branch master;
6. Each time you add a new project you need to login to the host through the shell and create a pure warehouse, we might as well as gitserver as a git user and the host name of the repository, if you run the host on the network, and set gitserver in DNS to point to the host, The following commands are available:
-M "Initial commit" git remote add origin git@GitServer:test1.gitgit push Origin master
Create a repository Repository
In this way, the clones and pushes of others are the same
git clone [email protected]:/ for the README file ' Git push Origin master
7. As an additional precaution, Git's own Git-shell tool can be used to limit the activity of git users to git-related only. Set it to the GIT user login shell, then the user can not have the host normal shell access, in order to achieve this, it is necessary to indicate that the user login shell for Git-shell, not bash or CSH, you can edit the/etc/passwd file
sudo vim/etc/passwd
At the end of the file, find a similar line
Git:x:1000:1000::/home/git:/bin/sh
Change Bin/sh to/usr/bin/git-shell
Git:x:1000:1000::/home/git:/usr/bin/git-shell
Now git users can only use SSH connections to push and get the Git repository, rather than using the host shell directly.
8. Q&a
(1)
Q:
[email protected]:~/myproject2$ git push Origin master
Agent admitted failure to sign using the key.
[email protected] ' s password:
ERROR:SRC Refspec Master does not match any.
Error:failed to push some refs to ' [email protected]:/opt/git/project.git/'
A: If the initial code warehouse is empty,git push Origin master submits the code with the above exception
http://www.linuxidc.com/Linux/2013-03/81022.htm
(2)
Q:
[email protected]:~/myproject2$ git push Origin master
Agent admitted failure to sign using the key.
[email protected] ' s password:
Permission denied, please try again.
[email protected] ' s password:
Counting Objects:3, done.
Writing objects:100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (Delta 0)
Error:insufficient permission for adding a object to repository database./objects
Fatal:failed to write Object
Error:unpack failed:unpack-objects Abnormal exit
to [email protected]:/opt/git/project.git/
! [Remote rejected] master, Master (N/A (unpacker error))
Error:failed to push some refs to ' [email protected]:/opt/git/project.git/'
A: The server has no permissions.
Http://blog.sina.com.cn/s/blog_53e449530101349s.html
http://stackoverflow.com/questions/1918524/ Error-pushing-to-github-insufficient-permission-for-adding-an-object-to-reposi
sudo chown-r git:gitgroup path/to/repo.git///-R git:git path/to/repo.git/
(3)
Http://www.linuxidc.com/Linux/2013-03/81022.htm
Q:
[email protected]:~/myproject2$ git push Origin master
Agent admitted failure to sign using the key.
[email protected] ' s password:
Counting Objects:3, done.
Writing objects:100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (Delta 0)
remote:error:refusing to update checked out Branch:refs/heads/master
Remote:error:By default, updating the current branch in a Non-bare repository
Remote:error:is denied, because it'll make the index and work tree inconsistent
Remote:error:with What do you pushed, and would require ' git reset--hard ' to match
Remote:error:the work tree to HEAD.
Remote:error:
Remote:error:You can set ' receive.denycurrentbranch ' configuration variable to
Remote:error: ' Ignore ' or ' warn ' in the remote repository to allow pushing into
Remote:error:its Current Branch; However, this isn't recommended unless you
Remote:error:arranged to update their work tree to match the what's pushed in some
Remote:error:other.
Remote:error:
Remote:error:To squelch This message and still keep the default behaviour, set
Remote:error: ' receive.denycurrentbranch ' configuration variable to ' refuse '.
to [email protected]:/opt/git/project.git/
! [Remote rejected] master, master (branch is currently checked out)
Error:failed to push some refs to ' [email protected]:/opt/git/project.git/'
A:
$cd. Git
$vim Config
The original contents of the configuration file are:
[Core]
repositoryformatversion = 0
FileMode = True
Bare = False
Logallrefupdates = True
Include the following in the configuration file:
[Receive]
Denycurrentbranch = Ignore
(4)
Linux server : Ubuntu config git service - Yat Yun Gull
Http://www.xue5.com/Server/Linux/667461.html
(5) In order to integrate into SCM, we install GIT on linxu
Http://www.examw.com/linux/all/182529/index-2.html
Create a GIT server on LINUX
http://lionest.iteye.com/blog/1447310
http://blog.csdn.net/andy_android/article/details/6996134
Receiving objects:26% (5668/21560), 8.06 MiB | 183 kib/s 21560)
(6)
Q:
[email protected]:~/myproject.git$ git push origin master Ssh:connect to host Xiongmc-desktop Port 22:connection refused
Fatal:the remote end hung up unexpectedly
[email protected]:~/myproject.git$ git push Origin master
Ssh:connect to host Xiongmc-desktop Port 22:connection refused
Fatal:the remote end hung up unexpectedly
A:
http://blog.csdn.net/zlm_250/article/details/7979221
sudo apt-get install Openssh-server
sudo net start sshd
sudo ufw disable
SSH localhost
(7)
Q:
under Ubuntu system " about ' xx ' users are not in the sudoers file, this matter will be reported. " The workaround
A:
Http://blog.sina.com.cn/s/blog_bede36550101b0av.html
git all= (all:all) all
(8)
Q:
[email protected]:~/myproject.git$ git push Origin master
[email protected] ' s password:
Fatal: '/opt/git/project.git ' does not appear to be a git repository
Fatal:the remote end hung up unexpectedly
A:
http://www.dotkam.com/2010/08/22/gitolite-does-not-appear-to-be-a-git-repository/
Linux Ubuntu build git server