How to set up private git server on linux

前端 未结 4 986
轮回少年
轮回少年 2021-01-31 12:30

I have tried following how-set-up-your-own-private-git-server-linux and private-remote-git-repositories-ubuntu-linode but I am still having problems.

My local environmen

相关标签:
4条回答
  • 2021-01-31 13:04

    I followed the most voted answer and I didnt get it to work. I found this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 and I got it working. I think the problem was that, in the server, the public key is to be copied to a file "authorized_keys" and not "authorized_hosts".

    0 讨论(0)
  • 2021-01-31 13:07

    I would like to recommend to use Gitolite that allows to setup git hosting on central srever with great features like access control and creating/managin repositories etc.

    And for windows, the tool called git-scm can be used for setting up git client and also have GUI panel for git repositories. After installation of this git tool, you will get a git bash tool and a git GUI.

    Gitolite makes settting up of a git hosting server and client very simple.

    I hope this may help new people who are looking for an efficient solution for settting up git hosting server and clients in some easy to understand simple steps.

    0 讨论(0)
  • 2021-01-31 13:09
    1. I had been trying to generate the key pairs using putty but couldn't get it to work. In the end I realised that I could generate the keys via the msysgit command line using ssh-keygen -C "git@example.com" -t rsa. Copy the public key to the server using nano /home/git/.ssh/authorized_keys and hey presto!
    2. I had downloaded the full source code hence the size! The non-source app, Git-1.7.4-preview20110204.exe was just 13MB via http://code.google.com/p/msysgit/downloads/list?can=3
    0 讨论(0)
  • 2021-01-31 13:17

    I'm not sure if this should be here or if it would be best migrated over to a different site, but since I might be able to help I'll go ahead and answer.

    I just skimmed the articles you linked. It looks like they both deal with accessing a git server over ssh, which you mention, so that's what I'll focus on.

    First, on your server:

    You need to set up an account on the server so that you can log in. This can be either a generic git account, or your own personal account. For the moment we'll assume that you are setting it up to work with a personal account. What you want to do is create your account, then somewhere accessible to that account (say, in your home directory), create the git repository.

    mkdir myrepo.git
    cd myrepo.git
    git --bare init --shared=all
    

    So now you have a git repository up on the server. Depending on the git client you are using, you might not need to mess with keys right now. If SSH is configured on your server to allow password login then you can probably just connect and enter your password when you need to interact with the server. If you want to set up keys, what you need to do is to generate an ssh public key. I don't know off hand how to do this in windows, but in linux you'd do something like:

    ssh-keygen -t rsa -b 1024
    

    That command will generate two files, "id_rsa" and "id_rsa.pub"; whatever tool you use should also generate two files, a public key and a private key. They might have different names, but assume for now that "id_rsa.pub" is the name of your public key file.

    You want to copy the public key to the server, you can use scp, ftp, or just move it over using a thumbdrive. Either way, once you get it onto the server, and it's accessible by your user, log in as your user on the server. You want to add the public key to your "authorized_hosts" file, so after logging in to your account on the server, do this:

    cd
    mkdir .ssh
    cat id_rsa.pub >> .ssh/authorized_hosts
    rm id_rsa.pub
    

    Now, from your workstation you need to configure your ssh client to use the private key your generated. Again, I don't know how to do this on Windows and it will probably vary depending on what ssh client you are using, so you'll need to get that information somewhere else.

    Next, you need to create your local repository, add some files, and make a commit. Note that you can't clone the remote repository you made yet because there's nothing in there. Once you have some commits made locally, you need to set the remote server in your repository.

    If you are using the git command line tools, you can run:

    git remote add origin user@yourserver:myrepo.git
    

    If you put the repository somewhere other than your home directory, use the full path:

    git remote add origin user@yourserver:/path/to/repo.git
    

    Note that you need the ".git" in there, since your directory name has ".git" as part of the name.

    If you are using a GUI tool, then you instead just edit the configuration file for the repository. This will be in the top level of your repository under ".git/config". You'll want to add something like

    [remote "origin"]
        url = user@yourserver:/path/to/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    Now that your remote is configured, and you have some commits locally, you can push your master branch up to the server. If you're using the command line use:

    git push origin master
    

    Or, if you're working on a different branch:

    git push origin mybranch
    

    If you are using a GUI frontend for get then you'll need to look up the documentation for that tool on how to push.

    0 讨论(0)
提交回复
热议问题