Mac 下 Git 的基礎(chǔ)命令行操作

因?yàn)镸ac下已經(jīng)自帶了git,所以我們跳過(guò)此步驟,如果你是Linux的其他系統(tǒng),可以使用一下代碼進(jìn)行安裝:

sudo apt-get install git-core //安裝Git

用戶配置

git config --global user.name "Your Name" //配置用戶名稱(chēng)
git config --global user.email "Your Email" //配置用戶郵箱
git config --list //查看配置信息

第一次初始化git版本庫(kù)
開(kāi)始一個(gè)新的項(xiàng)目,初始化新的代碼倉(cāng)庫(kù),要對(duì)現(xiàn)有的某個(gè)項(xiàng)目開(kāi)始用 Git 管理,只需到此項(xiàng)目所在的目錄,執(zhí)行:

git init

會(huì)在當(dāng)前目錄下生成一個(gè).git目錄,包含了所有g(shù)it需要的數(shù)據(jù)和資源
進(jìn)行g(shù)it添加,提交,推送操作

touch README //創(chuàng)建README
git add . //添加左右新增或者改動(dòng)過(guò)的文件
git commit -a -m "添加README" //提交變更到本地版本庫(kù)
git push origin <branch name> //推送本地版本庫(kù)到遠(yuǎn)程倉(cāng)庫(kù)

git克隆遠(yuǎn)程倉(cāng)庫(kù)

//Git本身的源代碼你既可以用 git:// 協(xié)議來(lái)訪問(wèn):
git clone git@git.jianshu.net:******/****.git
//也可以通過(guò)http 協(xié)議來(lái)訪問(wèn):
git clone https://git.jianshu.net/******/****.git
//自定義目錄名稱(chēng),如果不自定義,默認(rèn)為遠(yuǎn)程倉(cāng)庫(kù)的項(xiàng)目目錄名稱(chēng)
git clone https://git.jianshu.net/******/****.git mygrit

Git分支操作

查看分支 git branch
創(chuàng)建分支 git branch <branch name>
切換分支 git checkout branch
合并分支 git merge <branch name> //合并某分支到當(dāng)前分支
刪除分支git branch -d <branch name>

mac git --help
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)

clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)

add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)

bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history

branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)

fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 因?yàn)樵奶L(zhǎng)超出字?jǐn)?shù),Lesson 3 就放在另一篇文章里 How to Use Git and GitHub 標(biāo)...
    赤樂(lè)君閱讀 5,496評(píng)論 1 5
  • origin websiteComparing WorkflowsCentralized Workflow Fea...
    伍帆閱讀 572評(píng)論 0 0
  • 股指在經(jīng)歷了昨天的大幅下跌之后,今天兩市包括創(chuàng)業(yè)板都收紅了,其中深市和中小板、創(chuàng)業(yè)板表現(xiàn)要強(qiáng)于滬市,盤(pán)中反彈的主要...
    天天隨緣風(fēng)起閱讀 174評(píng)論 0 0
  • 現(xiàn)在是半夜11:53分,我坐在出租屋的床上,泡著腳。 昨天晚上本來(lái)想寫(xiě)點(diǎn)東西的,電腦都打開(kāi)了,點(diǎn)擊了瀏覽器,連“簡(jiǎn)...
    青木729閱讀 369評(píng)論 2 1
  • 在歸學(xué)校途中,在同和處難得擠了一班上班高峰期的地鐵,我好像懂得了什么叫做人生險(xiǎn)惡。 不要說(shuō)一席之地,有雙腳之地就謝...
    奶牛軟木閱讀 647評(píng)論 0 2

友情鏈接更多精彩內(nèi)容