Git 1-服务端搭建 Setting up a Git Server in CentOS 6.5

Setting up a Git Server in CentOS 6.5

Quick jump to: Create a git user account

Install git.

[root@svn ~]# yum install git

Add the developers group, all git users will be part of this group.

[root@svn ~]# groupadd developers

Create the git user which will own all the repos.

[root@svn ~]# useradd -s /sbin/nologin -g developers git_admin
[root@svn ~]# passwd git_admin
Changing password for user git.
New password: git********
Retype new password:git********
passwd: all authentication tokens updated successfully.

Update Permissions.

[root@svn ~]# chmod 2770 /home/git_admin/

Create an empty Git repo.

[root@svn root]# cd /home/git_admin && mkdir project1 && cd project1
[root@svn project1]# git init --bare --shared

Initialized empty shared Git repository in /home/git_admin/project1/

Update file ownership and permissions.

[root@svn project1]# chown -R git_admin .
[root@svn project1]# chmod 2770 /home/git_admin/project1

======== Create a git user account. =========

[root@svn git_admin]# useradd -s /usr/bin/git-shell -g developers -d /home/git_admin tony
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[root@svn git_admin]# passwd tony
Changing password for user tony.
New password: git********
Retype new password: git********
passwd: all authentication tokens updated successfully.

At this point a regular user should be able to checkout the project1 repo from the Git server.

tony@apha05:~$ mkdir ~/testing_shit/git_test
tony@apha05:~$ cd ~/testing_shit/git_test && git init
Initialized empty Git repository in /home/ubuntu/testing_shit/git_test/.git/
tony@apha05:~/testing_shit/git_test$ git remote add origin tony@xxx.xxx.xxx.xxx:/home/git_admin/project1

此时,如果你在apha05机器上 ~/testing_shit/git_test 目录下ls -all命令查看文件,会看到.git文件夹。

Now, let's create a readme.txt file in local git directory and commit it into local git repository.

tony@apha05:~$ cd ~/testing_shit/git_test && vim readme.txt
edit the contet like :" Git's a version control system . --by tony " and save this file.
tony@apha05: git_test$ git add readme.txt
tony@apha05: git_test$ git commit -m "wrote a readme file by tony"

[master (root-commit) a058fc9] wrote a readme file by tony
1 file changed, 1 insertion(+)
create mode 100644 readme.txt

Next, Push this commit upto remote git server:

tony@apha05: git_test$ git push origin master
The authenticity of host 'xxx.xxx.xxx.xxx' can't be established.
RSA key fingerprint is ??:??:??:??:??:??:??:??:??:??:??:??:??:??:??.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xxx.xxx.xxx.xxx' (RSA) to the list of known hosts.
tony@xxx.xxx.xxx.xxx's password:
Could not chdir to home directory /home/git: No such file or directory
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 299 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To tony@xxx.xxx.xxx.xxx:/home/git_admin/project1
* [new branch] master -> master

You can also test via git clone command:

tony@apha05: ~$ git clone tony@xxx.xxx.xxx.xxx:/home/git_admin/project1

  

Note:

before push your local repo upto remote server, you can do serveral changes for your code in git repo:

  • git add <file>  #add file into git repo
  • git commit -m "commit notes"
  • git status #check the status of git repo
  • git diff #check the differences, 如果git status告诉你有文件被修改过,用git diff可以查看修改内容。
  • git log #display the log
  • git reset #backward to previous versions
  • git reflog #check the history of git commands

 ref: http://www.cnblogs.com/GDUT-xiang/p/5706905.html
       Git远程操作详解
       Git Clients

#&

 

 

Published At
comments powered by Disqus