linux下使用git倉庫,以及使用github

2021-07-22 12:52:05 字數 2319 閱讀 8638

在linux下搭建git環境

1、建立github賬號,

2、linux建立ssh金鑰:

[plain]view plain

copy

ssh-keygen -t rsa -c "your_email.com"    ##一直預設就可以了  

3、將公鑰加入到github賬戶資訊account settings->ssh key

4、測試驗證是否成功。

[plain]view plain

copy

ssh -t [email protected]  

hi someone! you've successfully authenticated, but github does not provide shell access.  

同步github到本地

1、複製專案到本地:

[plain]view plain

copy

## ***x為你的github使用者名稱

## ***/*** 為:使用者名稱/github庫

git clone git: ##以gitreadonly方式轉殖到本地,只可以讀  

git clone [email protected]:***/test.git  ##以ssh方式轉殖到本地,可以讀寫  

git clone /***/test.git ##以https方式轉殖到本地,可以讀寫  

git fetch [email protected]:***/***.git  ##獲取到本地但不合併  

git pull [email protected]:***/***.git ##獲取並合併內容到本地  

本地提交專案到github

1、本地配置

[plain]view plain

copy

git config --global user.name 'onovps'  

git config --global user.email '[email protected]' #全域性****,可選  

2、新建git專案並提交到github。

[plain]view plain

copy

mkdir testdir & cd testdir  

touch readme.md  

git init #初始化乙個本地庫  

git add readme.md #新增檔案到本地倉庫  

git rm readme.md #本地倒庫內刪除  

git commit -m "first commit" #提交到本地庫並備註,此時變更仍在本地。  

git commit -a  ##自動更新變化的檔案,a可以理解為auto  

git remote add *** [email protected]:***/***.git  #增加乙個遠端伺服器的別名。  

git remote rm ***   ##刪除遠端版本庫的別名  

git push -u remotename master #將本地檔案提交到github的remoname版本庫中。此時才更新了本地變更到github服務上。  

分支版本操作

1、建立和合併分支

[plain]view plain

copy

git branch #顯示當前分支是master  

git branch new-feature  #建立分支  

git checkout new-feature  #切換到新分支  

vi page_cache.inc.php  

git add page_cache.inc.php  

git commit -a -m "added initial version of page cache"  

git push origin new-feature  ##把分支提交到遠端伺服器,只是把分支結構和內容提交到遠端,並沒有發生和主幹的合併行為。  

2、如果new-feature分支成熟了,覺得有必要合併進master

[plain]view plain

copy

git checkout master  #切換到新主幹  

git merge new-feature  ##把分支合併到主幹  

git branch #顯示當前分支是master  

git push  #此時主幹中也合併了new-feature的** 

linux下使用git建立遠端倉庫

公司有台伺服器閒置,正好可以做為我們的git伺服器來方便管理 在server端配置如下 apt get install git openssh server apt get install openssh clientuseradd git 使用git使用者管理 mkdir git git init...

Linux環境下Git的安裝以及使用

git 的工作需要呼叫 curl,zlib,openssl,expat,libiconv 等庫的 所以需要先安裝這些依賴工具。在有 yum 的系統上 比如 fedora 或者有 apt get 的系統上 比如 debian 體系 可以用下面的命令安裝 各 linux 系統可以使用其安裝包管理工具 a...

git在linux下建立倉庫

1,linux下建立git倉庫 yum install curl devel expat devel gettext devel openssl devel zlib devel perl devel yum install git 接下來我們 建立乙個git使用者組和使用者,用來執行git服務 g...