Git Start

此篇介绍Git基础操作。

quick start

git clone

1
2
3
4
5
6
7
8
9
$ git clone git@github.com:cutegentle/git-exercise.git
$ git-exercise git:(main) la
total 40
drwxr-xr-x 12 w staff 384B 9 21 17:43 .git
-rw-r--r-- 1 w staff 1.4K 9 21 17:43 .gitignore
-rw-r--r-- 1 w staff 11K 9 21 17:43 LICENSE
-rw-r--r-- 1 w staff 28B 9 21 17:43 README.md
$
$ git-exercise git:(main) ls

讲下工作区等概念,以及目录文件的一些用处。可结合sourcetree界面。

git log

1
2
3
$ git-exercise git:(main) git log
commit 128b182c3a76421ee5c321ad230579c53e9ec488 (HEAD -> main, origin/main, origin/HEAD)
$ q //quit

引用,commit等相关知识。

git status

1
2
3
4
5
6
7
8
9
10
$ git-exercise git:(main) git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
(use "git add <file>..." to include in what will be committed)
master1.txt

nothing added to commit but untracked files present (use "git add" to track)

git add & commit

1
2
3
4
5
6
7
8
$ git-exercise git:(main) ✗ git add .
$ git-exercise git:(main) ✗ git commit -m "main第一次本地提交"
$ git-exercise git:(main) git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)

nothing to commit, working tree clean

git push

1
2
$ git-exercise git:(main) git push origin
$ git-exercise git:(main) git push origin main

git pull

1
$ git-exercise git:(main) git pull origin main 

值得一提的是要注意HEAD,branch的指向。

以上为git最为基本的命令。需烂熟于心。


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!