1、官網注冊一個賬号 https://github.com
2、建立一個Repository
3、下載下傳Git用戶端 https://git-scm.com/downloads
4、基礎使用:
4.1 初始化項目
git init
4.2 添加檔案
git add abc.txt
4.3送出檔案
git commit -m 'first commit'
5、管理遠端倉庫
5.1 生成密匙
ssh-keygen -t rsa -C "[email protected]" //你的github郵箱賬戶
一路回車預設、打開密匙預設存放位置C:\Users\username\.ssh ,此檔案夾一共有兩個檔案id_rsa id_rsa.pub
用記事本或者指令行cat打開id_rsa.pub,複制密匙,進入Github網站--setting--ssh keys--建立,粘貼,生成
5.2本地連結
有兩種方式(1)https(2)ssh
推薦使用 ssh,因為https方式每次push都會輸入名字密碼,我們配置的密匙就沒有起到作用,用ssh方式可以使用密匙是以可以避免多次輸入名字密碼進行驗證。
ssh使用方式
git remote add origin [email protected]:it-chuan/test.git //it-chuan為你的使用者名,test.git為倉庫
5.3 上傳到遠端(上傳之前别忘了add、commit)
git push -u origin master
git remote -v
git remote rm origin
-
常用指令集合:
git init
建立版本庫 (生成例:/.git/目錄)
以下指令都需要擁有版本庫的時候才可以執行
git add <file>
用于把檔案添加到git(暫存區),準備送出【請忽略<>】
git add -A 或者 git add -all
把工作區的所有修改添加到暫存區
git commit -m '描述内容'
隻有添加檔案之後才能使用,用于送出内容到主分支(預設是master)
-
本地其它指令合集:
git status
檢視倉庫狀态
git diff
檢視修改的内容。注意:已經使用git add之後,不能再檢視修改的内容
git log
檢視git送出日志 記錄git commit資訊
git reflog
記錄每一次git的指令(該指令可用于復原後忘記最新版的id是找回)
HEAD 在git中指代目前版本 HEAD^指上一個,HEAD^^同理
git checkout -- <file>
撤銷檔案的修改到最近一次git commit或者git add 注意:--非常重要【請忽略<>】
git reset --hard <commit_id>
把工作區内容恢複到指定版本【請忽略<>】
git reset HEAD <file>
把暫存區的内容清除【請忽略<>】
git rm <file>
删除檔案。删除之後還需要送出(git commit)【請忽略<>】
git mv <filedir> <newfiledir>
移動檔案到新的路徑,如果新的檔案名發生改變,則可以了解為重命名【請忽略<>】
例子:git mv 12.txt 45.txt
把目前目錄下的檔案12.txt重命名為45.txt
git mv 45.txt ./dir/67.txt
把目前目錄下的檔案45.txt移動到目前目錄下的dir目錄中,并重命名為67.txt
-
遠端倉庫指令合集:
git remote add origin <address>
關聯一個github遠端倉庫 <address>是倉庫位址【請忽略<>】
git push -u origin master
關聯遠端倉庫第一次送出的時候添加上-u參數,用于把本地以前的commit_log推送到遠端庫
git push origin master
以後的推送就不需要-u參數
git remote rm origin
移除遠端庫
git remote add origin "Git倉庫的ssh格式位址"
添加遠端庫
git clone <adderss>
克隆一個已有的遠端倉庫。address是遠端庫位址【請忽略<>】
-
分支管理指令合集:
git checkout -b <newbranch>
建立一個新的分支并切換到這個新的分支。-b參數表示建立新分支 newbranch 新的分支名【請忽略<>】
git branch <newbranch>
建立一個新的分支,newbranch 新的分支名【請忽略<>】
git checkout <branch>
切換到指定分支【請忽略<>】
git branch
檢視目前倉庫擁有的分支,以及目前在哪一個分支(分支名前有*表示目前所在分支)
git merge <branch>
合并指定分支的更新到目前所在分支【請忽略<>】
git branch -d <branch>
删除指定分支【請忽略<>】
git branch -D <branch>
強制删除指定分支【請忽略<>】
-
其它指令集合:
git log --graph
顯示分支合并圖
git merge --no-ff <branch>
關閉Fast-forward 合并(快速模式),強制禁用快速合并模式進行合并指定分支到目前分支【請忽略<>】
git stash
儲存目前分支工作現場,可以執行多次
git stash list
檢視目前分支儲存的工作現場清單
git stash apply [stash_id]
恢複現場,方括号内是可選參數(指定恢複)【請忽略[]】
git stash pop [stash_id]
恢複現場,并删除【請忽略[]】
git stash drop [stash_id]
删除現場【請忽略[]】
git remote
檢視遠端庫資訊,預設顯示origin
git remote -v
檢視更詳細的遠端庫資訊,包括push 和fetch 位址
-
本文描述的指令還不是很全面,更詳細的請運作
git --help
查閱