Build a Git private server using Raspberry Pi

Source: Internet
Author: User

Recently I used Raspberry Pi to create a Git private server for all my Git repositories. I spent some time to make everything work correctly, but now it can run.

Install Git

First, install Git on Raspberry Pi.

Sudo apt-get install wget git-core

This will install the Git server and necessary client software.

Install SSH

If you have not installed SSH, run the following command to install it:

Sudo apt-get install ssh

Run the following command to start it:

Sudo/etc/init. d/ssh start

Now ssh is running, but once you restart Raspberry Pi, You need to execute the above command again. You can solve this problem by executing the following command:

Sudo update-rc.d ssh defaults

When you restart Raspberry Pi, SSH should be able to automatically start. You can see if you can connect to Raspberry Pi through SSH and use Putty on your Windows machine (Mac users need to find an alternative SSH client ).

Enter the IP address of Raspberry Pi in the HostName text box. Run the following command to find your Raspberry Pi IP Address:

/Sbin/ifconfig

Find inet addr: the IP address is next to it.

Change Host Name

This step is not required, but I strongly recommend that you plan to use multiple Raspberry Pi devices if you are working.

Sudo leafpad/etc/hostname

Enter the desired host name and save the file. My host name is "gitpi ".
Then, enter the following command:

Sudo leafpad/etc/hosts

Replace all "raspberrypi" with the new host name you entered in the previous step. Then restart your Raspberry Pi.

Add a "Git" user and group

Next we will create a "Git" user and user group. Note:/home/git is the folder I used in this example. If you want to use another path, replace "/home/git" in the following command ".

Adduser -- system -- shell/bin/bash -- gecos 'git version control by Pi' -- group -- home/git

Next, change the password:

Passwd git

Your "git" User now has a new password. Now, if you try to switch the user, you will see the prompt "git @ gitpi" for the user name and host on the current terminal ". You can use the following command to switch users:

Su git

Add an empty Git Repository (Git Repository)

Now let's add an empty Git repository.
First, change the directory to the path where you store git.

Cd/home/git

Create a folder for your repository, move it in, initialize and clear the repository.
Note that I am currently using a "git" user. This user has control over the/home/git directory.

Mkdir test. git
Cd test. git
Git -- bare init

Push your code to Pi

In the end, we will push the code to Raspberry Pi. First, change the path to your previously initialized git repository (or initialize a new one ).

Add a new remote host (* your IP address is not in brackets)

Git remote add pi git @ [your IP]:/home/git/test. git

Now you have to add your code, commit, and push.

Git add.
Git commit-am "Initial"
Git push pi master

If you get a message like this, "authenticity of host ..." You only need to enter "yes" and continue.
Ideally, if everything is normal, your Git repository has been built on your Raspberry Pi.

If you want to test it, try to clone your repository to your Windows machine. First, change the path to the location where you want to store clone (an empty folder), and then run the following command line (or git bash:

Git clone git @ [your IP]:/home/git/test. git

If you have any questions, please leave a message at your original blog address. Good luck!

Recommended reading:

Raspberry Pi build LAMP Server

Install a game simulator on Raspberry Pi

Install Weston on Raspberry Pi

Linux OS for Raspberry Pi is available

Raspberry Pi (Raspberry Pi) trial note

Introduction to Raspberry Pi (Raspberry Pi) installation, IP configuration, and software source

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.