git倉庫的基本操作

2021-07-07 02:10:08 字數 1852 閱讀 3415

1.建立倉庫

git init   一般建立本地倉庫使用

git init - -bare  初始化裸倉庫,伺服器上殘酷推薦建立裸倉庫,不能執行一些基本的git操作

2. 拷貝遠端倉庫

git clone  [倉庫位址]  -b [遠端分支名稱](可選)

clone之後,git會講遠端倉庫的名稱用別名  origin 表示

3. git add

git commit

git push origin [本地分支名稱]

比如: git push origin  branch-test  (

branch-test

為本地分支名稱)

origin只相當於乙個別名,代表的是遠端的倉庫,不是分支。執行git remote –v或者檢視.git/config可以看到origin的含義

git push 的完整語法為: git push  

repository 為遠端倉庫, 上面的例子中為: origin

refspec....  為分支資訊  +:src為本地分支。dst為遠端分支。 git push origin master中省略了  dst。預設時和local branch名字一樣。

4. 建立分支

建立本地分支

git branch [local name]   跟蹤預設的遠端分支

git branch[local name] [remote name]  建立跟蹤指定遠端分支的本地分支

刪除本地分支

git branch -d  [本地分支名稱]

建立遠端分支  

git push origin[本地分支名稱]  (將本地分支推送到遠端分支,也就建立了遠端)

刪除遠端分支 

git push origin :[遠端分支名稱]

git push origin :refs/for/test-remote   (:test-remote為遠端分支)注意分號的位置

參考:git 的origin和master分析

master其實是乙個「refspec」,正常的「refspec」的形式為」+:」,冒號前表示local branch的名字,冒號後表示remote repository下 branch的名字。注意,如果你省略了

,git就認為你想push到remote repository下和local branch相同名字的branch。聽起來有點拗口,再解釋下,push是怎麼個push法,就是把本地branch指向的commit push到remote repository下的branch,比如:

$git push origin master:master (在local repository中找到名字為master的branch,使用它去更新remote repository下名字為master的branch,如果remote repository下不存在名字是master的branch,那麼新建乙個)

$git push origin master (省略了

,等價於「git push origin master:master」)

$git push origin master:refs/for/mybranch (在local repository中找到名字為master的branch,用他去更新remote repository下面名字為mybranch的branch)

$git push origin head:refs/for/mybranch (head指向當前工作的branch,master不一定指向當前工作的branch,所以我覺得用head還比master好些)

$git push origin :mybranch (再origin repository裡面查詢mybranch,刪除它。用乙個空的去更新它,就相當於刪除了)

git 倉庫 基本操作命令

1.git clone url 轉殖 2.git status 檢視當前提交狀態 3.git add 加入所有檔案到專案 4.git commit m 專案名稱 初始化專案 提交到本地 5.git push 提交到伺服器 第4步完事也可以 git remote add origin yourgitu...

Git倉庫管理(1) 基本操作

git status 檢視當前分支的狀態 git diff 檢視當前分支的修改內容 git blame test.txt 檢視test.txt這個檔案的修改記錄 git add test.txt 將test.txt這個檔案新增到git管理 git rm test.txt 將test.txt這個檔案從...

git 倉庫操作

1.轉殖現有倉庫 git clone urlurl支援git ssh http https等各種協議 2.初始化乙個倉庫 git init在當前資料夾下生成 git目錄,完成初始化,此資料夾下的所有檔案都處於unstaged狀態 git檔案的各個狀態 1.unstaged git倉庫中沒有此檔案的相...