Hosting your Git repositories. This tutorial explains how to use Bitbucket as hosting provider for your Git repository and how you can install a Git server on your own machine.
Git allows you to host your own Git server. Instead of setting up your own server, you can also use a hosting service. The most popular Git hosting sites are GitHub and Bitbucket. Both offer free hosting with certain limitations.
Most Git (and Gerrit) servers support SSH based authentication. This requires a SSH key pair for automatic authentication.
An SSH key par consists of a public and private key. The public key is uploaded to the application you want to authenticate with. The application has no access to the private key. If you interact with the hosting provider via the ssh protocol, the public key is used to identify a user who encrypted the data during communication with the corresponding private key.
To create an SSH key under Linux (or Windows / Mac with OpenSSH
installed) switch to the command line and
The generated SSH
key is by default
located in the
directory of the user home directory. Ensure that you backup existing
before running the following commands.
# Switch to your .ssh directory cd ~/.ssh # If the directory # does not exist, create it via: # mkdir .ssh # Manually backup all existing content of this dir!!! # Afterwards generate the ssh key ssh-keygen -t rsa -C "email@example.com" # Press enter to select the default directory # You will be prompted for an optional passphrase # A passphrase protects your private key # but you have to enter it manually during ssh operations
The Eclipse IDE allows you to create an SSH key pair via.
It is good practice to use a
passphrase to protect your
private key. It
is also good practice to
operating system level permission settings
to ensure that only
owning user can access the
folder and its content.
In the above
The result will be two files,
which is your private key and
which is your public key.
You can specify alternative key names with the
additional configuration in the
will be picked up by
default. The following code shows an
Host *.eclipse.org IdentityFile ~/.ssh/eclipse.org Host *.github.com IdentityFile ~/.ssh/github.com
Bitbucket offers free hosting of public and private Git repositories.
Bitbucket allows unlimited public and private repositories. The number of participants for a free private repository is currently limited to 5 collaborators, i.e., if you have more than 5 developers which need access to a private repository you have to pay money to BitBucket.
You need to create a user via the web interface of Bitbucket. After creating this user you can create new repositories via the web interface.
After creating a new repository on BitBucket, you can use the following instructions connect a local Git repository with the BitBucket repository.
These instructions will be similar to the following commands.
# Global setup: # Set up git git config --global user.name "Your Name" git config --global user.email firstname.lastname@example.org # Next steps for a new repository mkdir gitbook cd gitbook git init touch README git add README git commit -m 'first commit' git remote add origin ssh://email@example.com/vogella/gitbook.git git push -u origin master # alternatively for an existing Git repo # add remote and push cd existing_git_repo git remote add origin ssh://firstname.lastname@example.org/vogella/gitbook.git git push -u origin master
As described before, you do not need a server. You can just use a file system or a public Git provider, such as GitHub or Bitbucket. Sometimes, however, it is convenient to have your own server, and installing it under Ubuntu is relatively easy.
First make sure you have installed the SSH tooling.
sudo apt-get install ssh
If you have not yet installed Git on your server, you need to do this too.
sudo apt-get install git-core
Create a new user and set a password for the Git system.
sudo adduser git
Now log in with your Git user and create a bare repository.
# Login to server # to test use localhost ssh git@IP_ADDRESS_OF_SERVER # Create repository git init --bare example.git
Now you can push to the remote repository.
mkdir gitexample cd gitexample git init touch README git add README git commit -m 'first commit' git remote add origin git@IP_ADDRESS_OF_SERVER:example.git git push origin master
The typical setup based on the created "git" user from above is
public SSH key of each user is added to the
file of the "git" user. Afterwards everyone can access the system
using the "git" user.
Alternatively you could use LDAP authentication or other special configurations.
The Git installation provides a specialized shell, which can be
assigned to the user. Typically this shell is located under in
and can be assigned to the user via the
configuration file to the Git user. If you assign this shell to the
Git user, this user can also perform git commands which add safety to
your Git setup.
|TRAINING||SERVICE & SUPPORT|
The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.
The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.
Copyright © 2012-2016 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.