Git

From KevinWiki

(Difference between revisions)
Jump to: navigation, search
Line 149: Line 149:
To see and edit all the config details
To see and edit all the config details
  $ git config -e
  $ git config -e
 +
 +
= Migration from SVN to Git =
 +
== Install git-svn ==
 +
$ apt-get install git-svn
 +
 +
== Prepare for Migration ==
 +
In some dir, create users.txt having all the user info
 +
e.g.)
 +
USERNAME = FirstName LastName <user@host>
 +
 +
== Migrate ==
 +
$ git svn clone --stdlayout --no-metadata -A users.txt --username=USERNAME https://svn.repo/project/trunk-folder project-tmp
 +
 +
$ cd project-tmp
 +
 +
$ git svn fetch
 +
 +
* To view the other SVN branches
 +
$ git branch -r
 +
 +
$ cd ..
 +
 +
$ git clone project-tmp project
 +
$ rm -Rf project-tmp
 +
 +
$ cd project
 +
$ git remote rm origin
 +
 +
* Before this, add git repo for the project first.
 +
$ git remote add origin git@git-repo:project
 +
 +
* To view all remote
 +
$ git remote -v
 +
 +
$ git config branch.master.remote origin
 +
$ git config branch.master.merge refs/heads/master
 +
 +
 +
* add user info to project/.git/config
 +
[user]
 +
  email = user@host
 +
 +
$ git push -u origin master
 +
 +
* Check status
 +
$ git status
 +
# On branch master
 +
nothing to commit (working directory clean)

Revision as of 11:25, 10 August 2012

Contents

Git

Client-side Installation

In the client,

$ apt-get install git-core 
$ git config --global user.name "GivenName Surname" 
$ git config --global user.email user@email.address 

Server-side Installation

In the server,

$ apt-get install git 

Gitolite

Add User to Manage Gitolite

  1. Add user to manage gitolite
$ adduser \
  --system \
  --shell /bin/bash \
  --gecos 'git version control' \
  --group \
  --disabled-password \
  --home /home/git \
  git

Adding system user `git' (UID 108) ...
Adding new group `git' (GID 110) ...
Adding new user `git' (UID 108) with group `git' ...
Creating home directory `/home/git' ...

Create SSH key

$ ssh-keygen -t rsa 

/home/username/.ssh/some_git_rsa [ENTER] [ENTER]

Transfer SSH Keys to Server

$ ssh-copy-id '-p PORT_NUMBER -i /home/user/.ssh/some_git_rsa.pub git_user@host' 

If it doesn't work because the user is the only user who can access the server with his/her ssh key so accessing with git_user doesn't work.

$ scp -P PORT ~/.ssh/some_git_rsa.pub user@host: 

Log in with the user account

$ ssh -p PORT user@host
$ mv some_git_rsa.pub git.pub 

Setup

$ su - git 
$ cd ~ 
$ echo "PATH=$HOME/bin:$PATH" >> ~/.bashrc 
  • don't need these 2 lines
$ mkdir .ssh 
$ cat /home/user/git.pub >> /home/git/.ssh/authorized_keys 
$ exit

Gitolite Installation

$ sudo -i 
$ apt-get install gitolite
[ENTER] -> :q to exit
$ exit

Setup git User

$ su - git
$ gl-setup /home/user/git.pub 
$ vim /etc/ssh/sshd_config 

Add git to the allowed user

AllowUsers user git

Restart ssh

$ service ssh restart 

Test

  • Testing (from user local machine)
$ ssh -p PORT_NUMBER git@host 

Having many keys?

$ ssh -p PORT_NUMBER -i ~/.ssh/user@host1.pub git@host 

For debugging

$ ssh -p PORT_NUMBER -vT git@host 
$ mkdir some-dir 
$ cd some-dir 
$ git clone git@host:gitolite-admin 

Or if you use a specific port,

$ git clone ssh://git@host:PORT_NUMBER/gitolite-admin

Add Git User (through Gitolite)

Adding User

$ cd gitolite-admin/keydir 
$ mkdir user_name 
$ cp -p ~/.ssh/user@host1.pub .
$ cp -p ~/.ssh/user@host2.pub .
$ git add user@host1.pub 
$ git commit -a -m "users added: user@host1 and user@host2" 
$ git push

Usage

Host Info Config using SSH_Config

Create ~/.ssh/config file and edit.

Host host.name
  Hostname host.name
  Port 1111

Host another.host.name
  Hostname another.host.name
  Port 2222

Host host1
  Hostname host.name
  Port 1111
  User git
  IdentityFile ~/.ssh/git_rsa

Host user-host2
  Hostname host2.name
  Port 1234
  User user
  IdentityFile ~/.ssh/user@localhost1

Host user-host3
  Hostname host3.com
  Port 1122
  User user
  IdentityFile ~/.ssh/user@localhost1

IdentityFile is a private key

To use this info,

$ git clone git@host1:repo-name 
# it will use 'git' as a user and access the server 'host.name' using the port nubmer 1111.
$ git clone git@host1:repo-name 
# it will use 'user' as a user and access the server 'host2.name' using the port nubmer 1234.

Push to Specific Host

$ git push git@host1:repo-name master

Set up Project Specific User Info

  • Move to the project repository
$ git config user.email user@email.address 

To see and edit all the config details

$ git config -e

Migration from SVN to Git

Install git-svn

$ apt-get install git-svn 

Prepare for Migration

In some dir, create users.txt having all the user info e.g.)

USERNAME = FirstName LastName <user@host>

Migrate

$ git svn clone --stdlayout --no-metadata -A users.txt --username=USERNAME https://svn.repo/project/trunk-folder project-tmp 
$ cd project-tmp 
$ git svn fetch 
  • To view the other SVN branches
$ git branch -r
$ cd ..
$ git clone project-tmp project 
$ rm -Rf project-tmp 
$ cd project 
$ git remote rm origin 
  • Before this, add git repo for the project first.
$ git remote add origin git@git-repo:project 
  • To view all remote
$ git remote -v 
$ git config branch.master.remote origin 
$ git config branch.master.merge refs/heads/master 


  • add user info to project/.git/config
[user]
  email = user@host
$ git push -u origin master 
  • Check status
$ git status 
# On branch master
nothing to commit (working directory clean)
Retrieved from "http://kevinlee.io/wiki/Git"
Personal tools