Category Archives: Git

Git: Server setup

git best guide
http://rogerdudler.github.io/git-guide/

 

How to setup a git server

git clone –bare my_project my_project.git
Cloning into bare repository ‘my_project.git’… done.
The output for this command is a little confusing. Since clone is basically a git init then a git fetch, we see some output from the git init part, which creates an empty directory. The actual object transfer gives no output, but it does happen. You should now have a copy of the Git directory data in your my_project.git directory.
cp -Rf my_project/.git my_project.git

Putting the Bare Repository on a Server

Now that you have a bare copy of your repository, all you need to do is put it on a server and set up your protocols. Let’s say you’ve set up a server called git.example.com that you have SSH access to, and you want to store all your Git repositories under the /opt/git directory. You can set up your new repository by copying your bare repository over:

$ scp -r my_project.git user@git.example.com:/opt/git

At this point, other users who have SSH access to the same server which has read-access to the /opt/git  directory can clone your repository by running

$ git clone user@git.example.com:/opt/git/my_project.git

Examples

Clone from upstream:

$ git clone git://git.kernel.org/pub/scm/.../linux.git my-linux
$ cd my-linux

Make a local clone that borrows from the current directory, without checking things out:

$ git clone -l -s -n . ../copy
$ cd ../copy
$ git show-branch

Clone from upstream while borrowing from an existing local directory:


$ git clone --reference /git/linux.git \
git://git.kernel.org/pub/scm/.../linux.git \
my-linux
$ cd my-linux

Create a bare repository to publish your changes to the public:

$ git clone --bare -l /home/proj/.git /pub/scm/proj.git

created a user for linux called git
everyone just install git on their machine
configure git with below command:


git config --global user.email "nandan.dubey@abcde.com"
git config --global user.name "Nandan Dubey"
git status
git add .
git commit -m "first commit"
$ git remote -v
origin ssh://git@10.0.0.31:/home/git/hello_world.git (fetch)
origin ssh://git@10.0.0.31:/home/git/hello_world.git (push)

now there are two ways for any project. either it is a brand new project. Correct for all project right now as git server repository is brand new so no projects exists right now.
So for brand new project first you need to create

git init hello_world

git remote remove origin

Instead of removing and re-adding, you can do this:

git remote set-url origin git://new.url.here

git clone –bare hello_world hello_world.git
scp -r hello_world.git git@10.0.0.31:/home/git
To copy an exisiting project use
git clone ssh://git@10.0.0.31:/home/git/hello_world.git
make changes do git add and git commit
finally do git push
git push origin master
folder files:
git init
git add .
git commit -m “first commit”
git remote add origin ssh://git@10.0.0.31:/home/git/test.git

Now, you can set up an empty repository for them by running git init with the –bare option, which initializes the repository without a working directory:

$ cd /opt/git
$ mkdir project.git
$ cd project.git
$ git --bare init

Then, John, Josie, or Jessica can push the first version of their project into that repository by adding it as a remote and pushing up a branch. Note that someone must shell onto the machine and create a bare repository every time you want to add a project. Let’s use git server as the hostname of the server on which you’ve set up your ‘git’ user and repository. If you’re running it internally, and you set up DNS for git server to point to that server, then you can use the commands pretty much as is:

# on Johns computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin ssh://git@10.0.0.31:/home/git/test.git
$ git push origin master

At this point, the others can clone it down and push changes back up just as easily:


$ git clone git@gitserver:/opt/git/project.git
$ cd project
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master

cd ~/.sshls -al# Lists the files in your .ssh directory

ssh-keygen -t rsa -C “your_email@example.com”# Creates a new ssh key, using the provided email as a label# Generating public/private rsa key pair.# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]

Enter passphrase (empty for no passphrase): [Type a passphrase]# Enter same passphrase again: [Type passphrase again]

Which should give you something like this:

# Your identification has been saved in /c/Users/you/.ssh/id_rsa.# Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.# The key fingerprint is:# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

Then add your new key to the ssh-agent:

ssh-add ~/.ssh/id_rsa

Run the following code to copy the key to your clipboard.

clip < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

ssh -T git@github.com# Attempts to ssh to github

ref: https://git-scm.com/

Advertisements