前言
一、github準備
- 註冊、登錄
- 添加ssh公鑰
- 創建遠程倉庫(git-in-action)
拉取代碼到本地
git clone [email protected]:shirayner/git-in-action.git
二、簡單的提交流程
(1)添加我們的代碼
這裏我們創建一個文件1.txt,然後裏面隨便寫上一段話。
(2)確認修改
λ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
1.txt
nothing added to commit but untracked files present (use "git add" to track)
(3)添加修改到暫存區
git add --all
(4)添加到本地倉庫
λ git commit -m"[ADD] 1.txt"
[master (root-commit) d8c62a5] [ADD] 1.txt
1 file changed, 1 insertion(+)
create mode 100644 1.txt
(5)提交到遠程倉庫
λ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 227 bytes | 227.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:shirayner/git-in-action.git
* [new branch] master -> master
三、分支
1.查看分支
λ git branch
* master
2.創建分支
創建分支
shira@ray ~/Desktop/mess/git-in-action (master)
λ git branch dev
shira@ray ~/Desktop/mess/git-in-action (master)
λ git branch
dev
* master
創建分支並切換到該分支上
shira@ray ~/Desktop/mess/git-in-action (master)
λ git checkout -b bug
Switched to a new branch 'bug'
shira@ray ~/Desktop/mess/git-in-action (bug)
λ git branch
* bug
dev
master
3.提交遠程對應的分支
添加修改
創建 bug.txt,內容任意
(1)確認修改
shira@ray ~/Desktop/mess/git-in-action (bug)
λ git status
On branch bug
Untracked files:
(use "git add <file>..." to include in what will be committed)
bug.txt
nothing added to commit but untracked files present (use "git add" to track)
(2)添加到暫存區
shira@ray ~/Desktop/mess/git-in-action (bug)
λ git add --all
(3)提交到本地倉庫
shira@ray ~/Desktop/mess/git-in-action (bug)
λ git commit -m"[ADD] bug.txt"
[bug 02c1cd1] [ADD] bug.txt
1 file changed, 1 insertion(+)
create mode 100644 bug.txt
(4)提交到遠程對應的分支
λ git push origin bug
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'bug' on GitHub by visiting:
remote: https://github.com/shirayner/git-in-action/pull/new/bug
remote:
To github.com:shirayner/git-in-action.git
* [new branch] bug -> bug