Git Server init

references:

http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository

Create git repository

//server side, you should have a common user account,  e.g., gituser:

$ mkdir /opt/git/project.git
$ cd /opt/git/project.git
$ git --bare init                //init a null project
$ git config --bool core.sharedRepository true

$ cd /opt/git/project.git
$ sudo chmod -R g+ws *
$ cd ..
$ sudo chown -R gituser:gituser project.git

//initial origin branch in a remote client:
$ mkdir my_git
$ cd my_git
$ git init
$ git add readme.txt
$ git commit -m "initialization for git server"
$ git remote add origin gituser@192.168.0.109:/opt/git/project.git
$ git push origin master

actually you can create a non-bare local repository first in server side, then clone a bare copy in server side, it is the same.
ok, now, git server is ready. you can get code freely from your workstation:

// first time

$ mkdir my_project

$ cd my_project

$ git clone gituser@192.168.0.109:/opt/git/project.git
// other times, for getting latest code:
$ cd my_project

$ git pull origin master



For example,

 HKmagazineAndroid.git has been inited in git server.

$ cd myproject

$ git init

$ git add .

$ git commit -m 'initial commit'

$ git remote add origin git@gitserver:/home/git/repo/HKMagazineAndroid.git

$ git push origin master
 
Others can clone it by:
 
git clone git@gitserver:/home/git/repo/HKMagazineAndroid.git

gitserver'sip is 10.80.1.117



git config配置文件

 

0. Git有一个工具被称为git config,它允许你获得和设置配置变量;

这些变量可以控制Git的外观和操作的各个方面.

有三种不同的方式来指定这些配置适用的范围:

1) git config                   xxpro/.git/config       针对一个git仓库

2) git config --global          ~/.gitconfig            针对一个用户

3) sudo git config --system     /etc/gitconfig          针对一个系统

因为是针对整个系统的,所以必须使用sudo.

三个配置文件的优先级是:xxpro/.git/config > ~/.gitconfig > /etc/gitconfig

 

1. ~/.gitconfig文件:具体到当前用户.你可以通过传递--global选项来读或写这

个配置文件.

2. 当你安装Git后首先要做的事情是设置你的用户和email地址.因为每次Git提交

都会使用该信息.

而且它被永远的嵌入到了你的提交中:

     $ git config--global user.name "Guo Liang"

     $ git config--global user.email "liang.guo@tieto.com"

3. 配置你的缺省文本编辑器,Git在需要你输入一些消息时会使用该文本编辑器.

缺省情况下,Git使用你的系统的缺省编辑器,这通常可能是vi或者vim.

     $ git config--global core.editor vim 4. Setup Command Alias(设置快捷命令)

     git config--global alias.st status

     git config--global alias.ci commit

     git config--global alias.co checkout

     git config--global alias.br branch

     git config--global alias.dc dcommit

     git config--global alias.rb rebase 5. Open Interactive Color(打开交互色彩)

     git config--global color.branch auto

     git config--global color.diff auto

     git config--global color.interactive auto

     git config--global color.status auto 6. Clone New Project(克隆新项目)

     git clonegit://gitorious.org/bamboo/mainline.git bamboo 7. Setup Remote Repository(设置远程仓库)

     # 添加(origin 为一个标示,可以随意更换)

     git remote addorigin git@gitorious.org:bamboo/mainline.git

     # 删除

     git remoteremove origin

8.Operations on Remote Repository(操作远程仓库)

     # 提交本地修改(将本地修改提交到远程的master分支

     git pushorigin master

     # 合并远程修改(将远程的master分支合并进来)

     git pullorigin master

     # 删除远程仓库里的分枝

     git push:branch

9. Basic Operations(基本操作)

     # 提交修改

     git add/path/to/file

     git commit -mreason

     # 提交全部修改

     git commit -a-m reason

     # 创建本地分枝

     git co -bbranch_name

     # 查看分枝

     git branch

     # 删除分枝

     git branch -Dbranch_name

     # 查看分支之间的差异

     git diffmaster branch

     # 查看最新版本和上一个版本的差异(一个^表示向前推进一个版本)

     git diff HEADHEAD ^

     # 查看状态

     git status

     # 合并分支

     git pull .branch

     # 销毁自己的修改

     git reset--hard

 

Add Repo  


#1. Server side Init

#1.1 work as adminstrator user: Create our source server dirtory
$ sudo mkdir -p /pub/gittrees/alk-snowball-repository/
$ sudo chown -R git:git /pub

#1.2 work as git user: Download the source mirror from internet
$ pwd
/home/git
$ mkdir snowball-src-mirror
$ cd snowball-src-mirror/
$ export MANIFEST_REPO=git://android.git.linaro.org/platform/manifest.git
$ export MANIFEST_BRANCH=linaro-android-12.03-release
$ export MANIFEST_FILENAME=landing-snowball.xml
$ repo init -u ${MANIFEST_REPO} -b ${MANIFEST_BRANCH} -m
${MANIFEST_FILENAME} --mirror
$ repo sync

#1.3 work as git user: Create our source mirror
$ cd /pub/gittrees/alk-snowball-repository/
$ repo init -u
git@10.80.1.55:/home/git/snowball-src-mirror/platform/manifest.git -b
${MANIFEST_BRANCH} -m ${MANIFEST_FILENAME} --mirror

#1.4 Modify the manifest.xml all remote repository to local server
before 'repo sync'
git@alkteam-server:/pub/gittrees/alk-snowball-repository/.repo/manifests$ git
diff
###############################################################################
git@alkteam-server:/pub/gittrees/alk-snowball-repository/.repo/manifests$ git
diff
diff --git a/landing-snowball.xml b/landing-snowball.xml
index 3b1df87..eb2ae37 100644
--- a/landing-snowball.xml
+++ b/landing-snowball.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
- <remote fetch="git://android.git.linaro.org/" name="aosp"
review="review.android.git.linaro.org"/>
- <remote fetch="https://android.googlesource.com/" name="aosp-upstream"/>
- <remote fetch="git://igloocommunity.org/" name="igloocommunity"/>
- <remote fetch="git://git.linaro.org/" name="linaro-other"/>
+ <remote fetch=".." name="aosp" review="review.android.git.linaro.org"/>
+ <remote fetch=".." name="aosp-upstream"/>
+ <remote fetch=".." name="igloocommunity"/>
+ <remote fetch=".." name="linaro-other"/>

<default remote="aosp" revision="refs/tags/android-4.0.3_r1" sync-j="4"/>
###############################################################################
$ repo sync

#2. Client Side Setup
$ pwd
/home/guooplia
$ mkdir snowball-source
$ cd snowball-source/
$ export MANIFEST_BRANCH=linaro-android-12.03-release
$ export MANIFEST_FILENAME=landing-snowball.xml
$ repo init -u
git@10.80.1.55:/pub/gittrees/alk-snowball-repository/platform/manifest.git
-b ${MANIFEST_BRANCH} -m ${MANIFEST_FILENAME}

#2.1 Modify the manifest.xml for local server and update the default.xml
$ cd /.repo/manifests
$ pwd
/home/guooplia/snowball-source/.repo/manifests
$ git reset --hard
# Modify the manifest.xml->landing-snowball.xml
# Update the landing-snowball.xml to default.xml
$ cp landing-snowball.xml default.xml

#2.2 commit manifest files changes to local server
$ git add .
$ git commit -a
$ git push
$ git pull
$ repo sync

#2.3 Create the our branch for manifest project
$ git checkout -b alkteam-snowball-4.0.3_r1
$ git push origin alkteam-snowball-4.0.3_r1

#2.4 Create the our branch for all projects
$ cd ../..
$ pwd
/home/guooplia/snowball-source
$ repo start alkteam-snowball-4.0.3_r1 --all
$ repo forall -c 'git remote add origin
git@10.80.1.55:/pub/gittrees/alk-snowball-repository/$REPO_PROJECT.git $@'
# $ repo forall -c 'git remote rm origin'
$ repo forall -c 'git push origin alkteam-snowball-4.0.3_r1'
$ repo sync

#3 Client Usage
$ repo init -u
git@10.80.1.55:/pub/gittrees/alk-snowball-repository/platform/manifest.git
-b alkteam-snowball-4.0.3_r1


br.
Grail


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值