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 [email protected]:/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 [email protected]:/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 "[email protected]"

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 [email protected]: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
[email protected]:/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
[email protected]:/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
[email protected]:/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
[email protected]:/pub/gittrees/alk-snowball-repository/platform/manifest.git
-b alkteam-snowball-4.0.3_r1


br.
Grail


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章