最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

git的基本用法

2023-03-01 10:26 作者:十年筑己  | 我要投稿

# git的基本用法


## 一、把本地倉庫(文件夾)放進(jìn)git管轄


說明:本教程里“倉庫”和“文件夾”是同義詞,建一個“倉庫”等同于建一個“文件夾”,程序員們在使用github時,相對更習(xí)慣用“倉庫”這個名稱。


### 第1步:配置自己的git


![image-20230223160531437](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160531437.png)


```PS C:\Users\Andy> git config --global [user.name](http://user.name/) "XXX" ``` (說明:引號里面填自己的github用戶名)


```PS C:\Users\Andy> git config --global user.email "XXX" ``` (說明:引號里面填自己注冊github時用的郵箱)


```PS C:\Users\Andy> git config --core.editor "code -w" ``` (說明:把Visual Studio Code設(shè)置為默認(rèn)編輯器。Visual Studio Code后面簡稱為“VS Code”)


### 第2步:在本地創(chuàng)建一個文件夾


使用命令:```mkdir learn-git```,創(chuàng)建一個名為“l(fā)earn-git”的文件夾


![image-20230223160559140](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160559140.png)


### 第3步:打開learn-git文件夾


使用命令:```cd learn-git```,打開“l(fā)earn-git”文件夾


![image-20230223160624645](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160624645.png)


### 第4步:初始化learn-git文件夾


使用命令:```git init```, 初始化learn-git文件夾


![image-20230223160700182](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160700182.png)


### 第5步:查看learn-git文件夾


使用命令:```ls```,查看learn-git文件夾下面的內(nèi)容,由于是剛創(chuàng)建,所以內(nèi)容為空。


說明:使用```git init```命令初始化“l(fā)earn-git”文件夾后,會生成一個后綴為.git的隱藏文件夾,使用一個特殊的命令:```ls -force```,可以看到這個被隱藏的文件夾


![image-20230223160728827](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160728827.png)


### 第6步:使用```git status```命令查看git狀態(tài)


對新手來說,這個操作很重要,我們需要從git的視角觀察文件夾里的變化情況


![image-20230223160754162](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160754162.png)


### 第7步:創(chuàng)建一個README.md的文件


使用命令```code README.md```創(chuàng)建一個文件,命名為“[README.md](http://README.md)”, 按回車,系統(tǒng)自動啟動Vs Code,在Vs Code界面下輸入內(nèi)容,然后保存,關(guān)閉Vs Code


![image-20230223160820770](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223160820770.png)


### 第8步:把經(jīng)過編輯的README.md提交到git的工作區(qū)


使用命令:```git add .```(注意,add后面有一個英文標(biāo)點狀態(tài)下“.”),把剛剛我們編輯過的README.md文件提交至git工作區(qū)。


說明:提交之后,可以再用```git status```命令查看git的狀態(tài),觀察前后的變化


![image-20230227145245131](https://gitee.com/andy116688/Typora/raw/master/img/image-20230227145245131.png)


![image-20230227145658726](https://gitee.com/andy116688/Typora/raw/master/img/image-20230227145658726.png)


### 第9步:把經(jīng)過編輯的README.md提交到git管轄


使用命令:```git commit```,把剛剛我們編輯過的README.md文件提交給git管轄,命令行界面會彈出關(guān)于本次提交的說明信息


![image-20230227145929523](https://gitee.com/andy116688/Typora/raw/master/img/image-20230227145929523.png)


### 第10步:在彈出來的Vs Code中填寫修改備注


![image-20230227145843705](https://gitee.com/andy116688/Typora/raw/master/img/image-20230227145843705.png)


在命令行輸入```git commit```命令后,系統(tǒng)會自動跳轉(zhuǎn)到Vs Code界面,我們需要在第一行填寫本次修改的備注信息,例如我在這里填寫的是“the second edition”,然后關(guān)閉Vs Code界面。


關(guān)閉Vs Code界面之后,回到命令行界面,再用git status命令查看git的狀態(tài),觀察前后的變化。


![image-20230227165627148](https://gitee.com/andy116688/Typora/raw/master/img/image-20230227165627148.png)


## 在github建一個遠(yuǎn)程倉庫


### 第1步:登陸自己的github賬號


github網(wǎng)址:https://github.com/


### 第2步:點右上角的“+”號


![image-20230223161545749](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223161545749.png)


### 第3步:點“New repository”


![image-20230223161728553](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223161728553.png)


### 第4步:在紅框處為該遠(yuǎn)程倉庫命名,如“l(fā)earn-git”


![image-20230223161810479](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223161810479.png)


### 第5步:點“Create repository” 創(chuàng)建倉庫


![image-20230223161956895](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223161956895.png)


創(chuàng)建倉庫時,為這個倉庫取個名字就行,github遠(yuǎn)程倉庫名稱可以和本地倉庫名稱一致,也可以不一致,對于初學(xué)者來說,建議讓本地文件夾名稱和github遠(yuǎn)程倉庫名稱保持一致,這樣方便我們學(xué)習(xí)。為倉庫完成命名后,當(dāng)前頁面的其他選項保持默認(rèn)狀態(tài),點擊最下方的“Create repository”按鈕。


## 三、把本地倉庫(文件夾)和github遠(yuǎn)程倉庫關(guān)聯(lián)


### 第1步:選擇本地倉庫和剛剛建立的github遠(yuǎn)程倉庫之間取得關(guān)聯(lián)的方式


接上面步驟,點擊“Create repository”之后,會彈出一個頁面,從上到下有三個選項,分別是:


**…or create a new repository on the command line(\**使用命令行創(chuàng)建一個新的倉庫\**)**


```jsx

echo "# leran-git" >> README.md

git init

git add README.md

git commit -m "first commit"

git branch -M main

git remote add origin <https://github.com/AndyZhou6688/leran-git.git>

git push -u origin main

```


**…or push an existing repository from the command line(把現(xiàn)存的本地倉庫push到github)**


```jsx

git remote add origin <https://github.com/AndyZhou6688/leran-git.git>

git branch -M main

git push -u origin main

```


**…or import code from another repository(從其他倉庫import代碼)**


You can initialize this repository with code from a Subversion, Mercurial, or TFS project.


本教程中采用的是**第二種**方式,即“**…or push an existing repository from the command line(把現(xiàn)存的本地倉庫push到github)**”


![image-20230223164514422](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223164514422.png)


### 第2步:把本地倉庫push到github


```jsx

git remote add origin <https://github.com/AndyZhou6688/leran-git.git>

git branch -M main

git push -u origin main

```


在當(dāng)前工作目錄下(剛剛創(chuàng)建的README.md文件所在的目錄),這點很重要,千萬不要弄錯。


“git remote add origin https://github.com/AndyZhou6688/leran-git.git”這句話的意思是:讓本地創(chuàng)建的倉庫和github上創(chuàng)建的那個遠(yuǎn)程倉庫關(guān)聯(lián)起來。


“git push -u origin main” 這句話的意思是把本地倉庫(文件夾)push(推)上github遠(yuǎn)程倉庫


### 第3步:輸入自己github倉庫的賬號和密碼


如果配置了SSH登錄,可以省去這個步驟。


### 第4步:刷新自己github上的“l(fā)earn-git”倉庫


刷新后,可以看到我們在本地創(chuàng)建的“README.md”文件顯示在github中“l(fā)earn-git”這個倉庫里了。


![image-20230223165517901](https://gitee.com/andy116688/Typora/raw/master/img/image-20230223165517901.png)


如果您完成了以上全部的步驟,恭喜,您又學(xué)會了一項新技能!


git的基本用法的評論 (共 條)

分享到微博請遵守國家法律
常宁市| 手游| 山东省| 靖宇县| 剑阁县| 岳池县| 喀喇沁旗| 台山市| 惠来县| 九龙城区| 新建县| 栾川县| 武穴市| 贡觉县| 开原市| 江西省| 曲周县| 收藏| 泽州县| 交口县| 香港| 兴安盟| 锡林郭勒盟| 崇明县| 普定县| 中方县| 凤城市| 辽中县| 黄陵县| 应城市| 洛隆县| 揭西县| 衡阳县| 胶州市| 周至县| 沁阳市| 乌鲁木齐市| 德清县| 恩平市| 介休市| 台山市|