git# 建立個人級服務器倉庫 git init --bare


學習或則測試一些git命令的效果,你可以使用github這種服務商,也可以自己建立服務器倉庫。而后者更方便、快捷也更能體會git到底是什么。

 

建立個人級服務器倉庫

 % mkdir -p ~/git/testgit.git                                             
 % cd ~/git/testgit.git                                                   
 % git init --bare                                 
Reinitialized existing Git repository in /home/matt/git/testgit.git/
 % ls                                               
branches/  config  description  HEAD  hooks/  info/  objects/  refs/

通過ls命令可以看出:git init --bare 初始化的目錄等同於一個.git目錄的內容。這樣就比較好理解git的本質:本地倉庫的.git和服務器倉庫。它們是一回事情。

 

連接提交到個人倉庫服務器

% mkdir -p ~/tmp/testgit
% cd ~/tmp/testgit
% git init                                               
Initialized empty Git repository in /home/matt/tmp/testgit/.git/       
% touch README               
 % git add .                                        
 % git commit -m "initial commit"      
[master (root-commit) 02ecfad] initial commit                                       
 0 files changed                                                                   
 create mode 100644 README                                                           
 % git remote add origin localhost:/home/matt/git/testgit.git                         
 % git push -u origin master                  
Counting objects: 3, done.                                                            
Writing objects: 100% (3/3), 205 bytes, done.                                         
Total 3 (delta 0), reused 0 (delta 0)                                                 
To localhost:/home/matt/git/testgit.git                                               
 * [new branch]      master -> master                                                 
Branch master set up to track remote branch master from origin.     

這幾條命令就把一個簡單的本地倉庫提交到個人的服務器倉庫上了。

其中的重點是 git remote add origin localhost:/home/matt/git/testgit.git

這條命令隱含了幾個ssh的知識點。熟悉它,可以幫助我們理解通常的git地址

1. git地址其實就是個ssh地址

2. ssh省略用戶的話會假定是當前用戶。

  比如這個例子,完整的ssh連接是: matt@localhost:/home/matt/git/testgit.git

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM