【git】記錄從倉庫創建到代碼提交的完整過程

創建遠程倉庫

GItHub 上創建代碼倉庫
在這裏插入圖片描述
創建成功後,出現如下頁面,展示該倉庫的遠程地址以及使用方法。
在這裏插入圖片描述

創建本地倉庫

創建目錄

$ mkdir -p git_origin

進入目錄並關聯遠程倉庫

$ cd git_origin

$ git clone [上圖中遠程倉庫的地址-項目名爲test_project]
Cloning into 'test_project'...
warning: You appear to have cloned an empty repository.

確認拉取成功

$ ls
test_project

在本地倉庫新建代碼

因爲目前該項目爲空倉庫,創建文件並提交

$ cd test_project
$ echo "# README" >> README.md

$ git add .
$ git commit -m "first commit"
*** Please tell me who you are.
...
fatal: unable to auto-detect email address

這裏並沒有提交成功,還需要配置賬戶信息:

$ git config --global user.email "[email protected]"
$ git config --global user.name "Your Name"

配置後再次提交後,成功提交,自動生成 master分支,通過命令查看, * 代表目前所處的分支。

$ git branch
* master

目前本地倉庫的代碼已提交到本地的 master 分支,遠程倉庫還沒有 readme.md 文件。

同步文件到遠程倉庫

$ git push origin master:master
...
 * [new branch]      master -> master

此處還需要輸入 github 的賬號和密碼,才能成功提交。

提交成功後,刷新遠程倉庫頁面,即可看到提交的代碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章