Mac build git server

Source: Internet
Author: User
Tags file copy python script

http://blog.csdn.net/kesalin/article/details/6943770

XCode 4 supports Git as a code repository by default, and when we create a new repository, we can tick the default repository, but the repository is local. This article describes how to create a git server on a Mac machine, the general idea is to use gitosis to simplify the creation process, create an account called Git on the machine used as a server to create a git server, and other clients to access the GIT server via SSH.

This document: Click here to download

One, create a git account
1. Create a git account on the machine server that is used as the server. We can add them through the System preferences->accounts. Here I add a git administrator account, Administrator is not required, here just for convenience.

2, set remote access
Logout your current account, log in with your Git account, and in System preferences->sharing, tick: Web sharing and Remote logig.

Second, download and install Gitosis
1,mac Snow by default, Git and Python have been installed for us, and you can use the following command to view its version information:

yourname:~ git$ git--version
git version 1.7.3.4
yourname:~ git$ python--version
Python 2.6.1


2, download gitosis by command "Git clone git://eagain.net/gitosis.git"

yourname:~ git$ git clone git://eagain.net/gitosis.git
Cloning into gitosis
Remote:counting objects:614, done.
Remote:compressing objects:100% (183/183), done.
Remote:total 614 (Delta 434), reused 594 (Delta 422)
Receiving objects:100% (614/614), 93.82 KiB | KIB/S, done.
Resolving deltas:100% (434/434), done.


3. Go to the Gitosis directory and use the command "sudo python setup.py install" to execute the Python script installation gitosis.

yourname:~ git$ CD gitosis/
Yourname:gitosis git$ sudo python setup.py install
Running Install
Running Bdist_egg
Running Egg_info
Creating Gitosis.egg-info
......
Using/library/python/2.6/site-packages/setuptools-0.6c9-py2.6.egg
Finished processing dependencies for gitosis==0.2


Third, make SSH RSA public key
1, go back to the client machine and make the SSH public key. Here I use another account on the same machine as the client. If the machine as a client is not the same as the machine for the server, it is also a type of process: make the public key and place it in the/tmp directory of the service. Just on the same machine, we can operate two accounts simultaneously by turning on another terminal and using SU to switch to a local account.

yourname:~ git$ su Local_account
Password:
bash-3.2$ CD ~
bash-3.2$ ssh-keygen-t RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/USERS/LOCAL_ACCOUNT/.SSH/ID_RSA):
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/users/local_account/.ssh/id_rsa.
Your public key has been saved in/users/local_account/.ssh/id_rsa.pub.

bash-3.2$ CD. SSH
bash-3.2$ ls
Id_rsa id_rsa.pub
bash-3.2$ CP id_rsa.pub/tmp/ Yourame. pub


In the above command, first through the SU switch to the local account (only valid on the same machine), then into the local account home directory, using ssh-keygen-t RSA to generate ID_RSA.PUB, and finally put the file copy to/tmp/yo Urname.pub, so the GIT account can access the Yourname.pub, renamed here to make it easier to identify multiple clients in Git.

Four, initialize gitosis with SSH public key
1, whether you are in that way (mail, USB, etc.) copy yourname.pub to the server/tmp/yourname.pub. The following process is the same, login to the server machine's git account, into the previously mentioned Gitosis directory, to do the following initialization gitosis, after the initialization is completed, will be in the GIT home under the repositories directory created.

Yourname:gitosis git$ sudo-h-u git gitosis-init </tmp/yourname.pub
Initialized Empty Git repository in/users/git/repositories/gitosis-admin.git/
reinitialized existing Git repository in/users/git/repositories/gitosis-admin.git/


In this case, the client will be treated as a trusted account, so there will be records in the Git home directory, and the file Authorized_keys content is similar to yourname.pub.

yourname:~ git$ CD ~
yourname:~ git$ CD. SSH
YOURNAME:.SSH git$ ls
Authorized_keys


We need to change authorizd_keys slightly, open it with a text editor, delete the "command=" Gitosis-serve yourname ", no-port-forwarding,no-x11-forwarding, No-agent-forwarding,no-pty "This line:

Yourname:.ssh git$ open-e Authorized_keys

We then give the post-update a writable permission so that the client can commit the changes.

Yourname:gitosis git$ sudo chmod 755/users/git/repositories//gitosis-admin.git/hooks/post-update
Password:
Yourname:.ssh git$ CD ~
yourname:~ git$ CD repositories/
Yourname:repositories git$ ls
Gitosis-admin.git
Yourname:repositories git$


As you can see in the above command, Gitosis is also given as a repository, we can checkout in other accounts, then configure management of Gitosis, and so on, without using the server's Git account.

The last step is to modify the path of the GIT account.

Yourname:gitosis git$ Touch ~/.BASHRC
Yourname:gitosis git$ echo path=/usr/local/bin:/usr/local/git/bin:\ $PATH >. BASHRC
Yourname:gitosis git$ Echo Export PATH >> BASHRC
Yourname:gitosis git$ Cat. BASHRC
Path=/usr/local/bin:/usr/local/git/bin: $PATH
Export PATH


At this point, the configuration of the server is complete.

Five, client Configuration
1, back to the local account, first change the local git configuration by entering the following command in Terminal:

bash-3.2$ git config--global user.name "Yourgitname"
bash-3.2$ git config--global user.email "[Email protected]"


2, the test server is connected correctly, the 10.1.4.211 is replaced with the name of your service or server address.

yourname:~ local_account$ ssh [email protected]
Last Login:mon Nov 7 13:11:38 from 10.1.4.211


3, in the local clone server warehouse, take Gitosis-admin.git as an example:

bash-3.2$ git clone [email protected]:repositories/gitosis-admin.git
Cloning into Gitosis-admin
Remote:counting Objects:5, done.
Remote:compressing objects:100% (5/5), done.
Remote:total 5 (Delta 0), reused 5 (Delta 0)
Receiving objects:100% (5/5), done.
bash-3.2$ ls
Desktop Installapp Music Sites
Documents Library Pictures Gitosis-admin
Downloads Movies Public
bash-3.2$ git


As you can see in the output above, we have successfully gitosis-admin the clone server to the local repository.

4, in the local management gitosis-admin:
To enter the Gitosis-admin directory, let's look at its directory structure: The gitosis.conf file is a configuration file that defines which users can access which repositories, and we can modify this configuration; Keydir is where the SSH public key resides.

bash-3.2$ CD gitosis-admin/
bash-3.2$ ls
Gitosis.conf Keydir
bash-3.2$ CD keydir/
bash-3.2$ ls
Yourname.pub

We only need to add the SSH public key generated by the other client to the Keydir directory and configure the repository that these users can access in the gitosis.conf file (the user name is the same as the SH public key name placed under Keydir, which is why we want to modify the SSH public key name in the previous section). Then commit the changes to the server, so that other client side access to the server's code warehouse. --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --

1) Create an empty repository on the server side

$ CD Path/to
$ mkdir newrepo.git$ cd newrepo.git$ git init--bare
#--bare flag is only used to store pushes and will not be used as a local repository.

2) on the client side, create the local repository and push

$ cd path/to$ mkdir newrepo$ cd newrepo$ git init$ touch readme$ git Add. $ git commit-m "initial commit" $ git remote add Origin [Email Protected]:/path/to/newrepo.git # If the newrepo.git created directly before the server side is in the home directory, the address here is:[email protected]:n Ewrepo.git
$ GIT push origin master

Mac build git server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.