Git命令進行GitHub的互動

2021-07-11 19:21:12 字數 2654 閱讀 7578

在使用github進行**託管時候,我們用git命令進行**的互動操作,首先在github建立乙個賬戶並建立專案倉庫。本次主要講述通過git命令進行互動。

建立了乙個**倉庫test,建立完成後如下圖

(1)用clone命令轉殖github的倉庫到本地倉庫

git clone
(2)配置使用者名稱和郵箱在使用git時候需要設定使用者名稱和郵箱,分為全域性配置或單個倉庫配置(需要在當前專案下配置)。注:如果沒有配置單個倉庫的使用者名稱和郵箱,則使用全域性配置的。

全域性配置如下:

git config --global user.name "github's name"

git config --global user.email "[email protected]"

單個倉庫配置如下:

git config user.name

"gitlab's name"

git config user.email

"[email protected]"

採用以下命令檢視當前配置, 在當前專案下面檢視的配置是全域性配置+當前專案的配置, 使用的時候會優先使用當前專案的配置

git

config--

list

例如本次配置單個倉庫的使用者名稱和郵箱

git config user.name "[email protected]"

git config user.email "[email protected]"

(3)新增提交**同步到遠端伺服器在本地倉庫新建檔案(例如**等),然後採用以下一系列命令進行提交

git add .

git commit -m "初次提交"

git push -u origin master

add命令用「.」代表提交本資料夾下的所有,也可以提交單獨的檔案,寫具體的檔名即可。

採用上述後輸入github的個人賬戶和密碼即可提交成功。提交成功後登陸網頁檢視是否提交成功!

注:clone後首次push,採用git push可能會出現:

$ git push  

no refs in common and

none specified; doing nothing.

perhaps you should specify a branch such as

'master'.

fatal: the remote end

hung

upunexpectedly

error: failed to push some refs to

'file:/'

此時採用 git push origin master 即可

(4)提交修改檔案

當檔案修改後提交同步到遠端伺服器,同上新增過程

git add .

git commit -m "更新提交"

git push -u orgin master

(5)刪除檔案或資料夾

在資料夾裡直接刪除檔案或資料夾

git commit -a

-m"刪除檔案或資料夾"

git push -u orgin master

(6)從遠端伺服器上更新本地**

git pull 更新當前分支

git pull origin master 更新 origin remote 的 master 分支

git fetch 獲取伺服器端的改動,比如其他使用者新建了乙個分支並push到了伺服器,執行這個命令之後會得到這個分支的資訊

(7)用遠端伺服器上**覆蓋本地**方法一

git

fetch--

allgit

reset--

hard

origin/master

方法二

git

reset--

hard

head

gitpull

注:

其他一些常用命令:

git init 建立乙個空的git庫

git status 檢視當前的git 狀態:檢視git庫中發生的改變

Git 與 Github進行關聯

1 給本地git配置全域性屬性user.name user.email github 的賬號 git config global user.name your name git config global user.email your email youremail.com 2 在本地建立ssh ...

github常用的git命令

新增已有專案到github touch readme.md 新建說明檔案 git init 在當前專案目錄中生成本地git管理,並建立乙個隱藏.git目錄 git add 新增當前目錄中的所有檔案到索引 git commit m first commit 提交到本地原始碼庫,並附加提交注釋 新增到遠...

git基礎命令 gitHub

git 和 github git 本地專案版本管理工具 雙擊一直下一步,就可以 安裝成功之後,滑鼠右鍵點選 如果出現 git gui here git bash here 證明安裝成功 首次使用git,要先在 cmd中 執行相關的設定操作,完成初始化 git config list 檢查 git 全...