Git入門操作

來源:互聯網
上載者:User

標籤:

僅學習Git的一些入門操作比較容易,平時更多地使用GitHub,不過今天我想自個搭個服務練練手。當看完一些材料合作了一些驗證之後,才發現其實所謂的服務和之前的svn完全不一樣了。過程記錄如下:

LinuxServer端安裝git

我把服務打在Linux機器上,這台破機器沒有apt-get,沒有yum,只好自己下載源碼,自己編譯 

$ wget http://distfiles.macports.org/git/git-2.5.3.tar.gz$ tar xzvf git-latest.tar.gz $ cd git-{date} $ autoconf $ ./configure --with-curl=/usr/local $ make $ make install

還好一路順利:

$ git --versiongit version 2.5.3

 

Server端ssh配置 

1)如果client端沒有建立ssh rsa公開金鑰,則先建立:

$ cd ~$ ssh-keygen -t rsa    # 預設存放路徑在~/.ssh/id_rsa.pub

2)如果client端已建立,並存在~/.ssh/id_rsa.pub,則將其拷貝到server端:

$ ssh <username>@<server_ip>:.ssh/authorized_keysid_rsa.pub                                    100%  416     0.4KB/s   00:00 

3)修改Server端的sshd_config:

$ ssh <username>@<server_ip>$ cd /etc            # 有的機器在/etc/ssh下面$ sudo chmod 666 sshd_config$ vi sshd_config#PermitRootLogin yes     改為 PermitRootLogin no# 下面幾項把前面的 #注釋 去掉#RSAAuthentication yes#PubkeyAuthentication yes#AuthorizedKeysFile     .ssh/authorized_keys#PasswordAuthentication no#PermitEmptyPasswords no#UsePAM yes          改為 UsePAM no 

 

測試是否有效

1)在Server端建立空的repository

$ cd repo$ git init —bare    # —bare flag 只是用來儲存pushes,不會當做本地repository來使用的。

2)在Client端建立repository 並push

$ mkdir localrepo$ cd localrepo$ git init$ touch README$ git add .$ git commit -m “add README”$ git remote add origin <username>@<server_ip>:/repo$ git push origin master

3)在Client端clone剛剛建立的repository

$ git clone <username>@<server_ip>:/repo localrepo2

發現剛剛提交的代碼樹被clone下來,說明搭建成功

 

由於git是分布式的,沒有主從之分,所以我理解所謂搭建git服務,其實就是確保有許可權訪問“伺服器”上的git檔案。這與該檔案是在遠程還是本地是無關的。比如上面的例子中,如果我把伺服器放在本地,一樣是可以的。

驗證伺服器搭建在本地

1)在本地建立空的repository

$ mkdir ~/repo$ cd ~/repo$ git init —bare

2)在本地建立repository 並push

$ mkdir ~/localrepo$ cd ~/localrepo$ git init$ touch README$ git add .$ git commit -m “add README”$ git remote add origin ~/repo$ git push origin master

3)在本地clone剛剛建立的repository

$ git clone ~/repo ~/localrepo2

查看~/localrepo2,果然README被複製過來了。

 

參考資料:

http://www.cnblogs.com/eileenleung/p/3503337.html

 

 

 

 

Git入門操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.