Git原理(03)

18. 本地分支和远程分支

新建文件夹,将远程仓库克隆到本地

image-20210824083327654

1
2
3
4
5
6
7
8
9
xiong@Surface-pro6 MINGW64 /c/Files/git-clone
$ git clone https://github.com/xiongzhuozhuo/2021-git-demo.git
Cloning into '2021-git-demo'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 17 (delta 3), reused 10 (delta 1), pack-reused 0
Receiving objects: 100% (17/17), 4.28 KiB | 548.00 KiB/s, done.
Resolving deltas: 100% (3/3), done.

克隆的仓库只有一个master分支,且是默认分支

image-20210824084144741

克隆完远程仓库后,本地仓库也会新建出一个master分支 ,这个分支就是远程仓库的默认分支。

①查看本地分支git branch

1
2
3
4
5
6
xiong@Surface-pro6 MINGW64 /c/Files/git-clone
$ cd 2021-git-demo/

xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git branch
* master

②查看远程分支git branch -r

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git branch -r
origin/HEAD -> origin/master
origin/master

③查看refs

1
2
3
4
5
6
7
8
9
10
11
12
13
xiong@SURFACE-PRO6 C:\Files\git-clone\2021-git-demo
$ tree .git/refs /f
卷 Local Disk 的文件夹 PATH 列表
卷序列号为 C0000100 F296:2801
C:\FILES\GIT-CLONE\2021-GIT-DEMO\.GIT\REFS
├─heads
│ master #本地分支

├─remotes #远程分支
│ └─origin
│ HEAD

└─tags

④refs里只有远程的HEAD,没有远程的分支,远程的分支被放在了packed-refs里了,查看该文件内容

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ cat .git/packed-refs
# pack-refs with: peeled fully-peeled sorted
70795aa27f962c60c6c139dcb390492cf5f6b615 refs/remotes/origin/master

文件存储了远程的master分支所指向的commit

⑤查看提交历史

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git log
commit 70795aa27f962c60c6c139dcb390492cf5f6b615 (HEAD -> master, origin/master, origin/HEAD)
Author: xiong <68106285+xiongzhuozhuo@users.noreply.github.com>
Date: Sun Aug 22 12:26:02 2021 +0800

Update README.md

commit 7a2612b3ae1e6fd6824781d3dd921608adb6a619
Author: xiong <68106285+xiongzhuozhuo@users.noreply.github.com>
Date: Sun Aug 22 12:16:09 2021 +0800

Create README.md

commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800

3rd commit

commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800

2nd commit

commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800

1st commit

模拟远程仓库有人进行提交

①仓库的初始情况

1
2
3
4
5
6
7
8
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ cat .git/packed-refs
# pack-refs with: peeled fully-peeled sorted
70795aa27f962c60c6c139dcb390492cf5f6b615 refs/remotes/origin/master

xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ cat .git/refs/heads/master
70795aa27f962c60c6c139dcb390492cf5f6b615

远程分支与本地分支指向的commit相同

②在远程仓库修改file1.txt

image-20210824093058140

image-20210824093235863

查看远程的origin

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ cat .git/packed-refs
# pack-refs with: peeled fully-peeled sorted
70795aa27f962c60c6c139dcb390492cf5f6b615 refs/remotes/origin/master

使用git fetch与远程进行同步

1
2
3
4
5
6
7
8
9
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 648 bytes | 64.00 KiB/s, done.
From https://github.com/xiongzhuozhuo/2021-git-demo
70795aa..278dcf6 master -> origin/master

再次查看远程origin:仍未发生改变

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ cat .git/packed-refs
# pack-refs with: peeled fully-peeled sorted
70795aa27f962c60c6c139dcb390492cf5f6b615 refs/remotes/origin/master

查看refs:出现了master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
xiong@SURFACE-PRO6 C:\Files\git-clone\2021-git-demo
$ tree .git/refs /f
卷 Local Disk 的文件夹 PATH 列表
卷序列号为 C0000100 F296:2801
C:\FILES\GIT-CLONE\2021-GIT-DEMO\.GIT\REFS
├─heads
│ master

├─remotes
│ └─origin
│ HEAD
│ master

└─tags

查看master:指向的是最新的一次提交

1
2
3
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ cat .git/refs/remotes/origin/master
278dcf612bf8e033a15c9b429adbb32b0a9210b6

出现的原因,packed-refs不是实时的压缩,是在某个时间点进行的,所以不同步。


在本地查看提交历史

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git log
commit 70795aa27f962c60c6c139dcb390492cf5f6b615 (HEAD -> master)
Author: xiong <68106285+xiongzhuozhuo@users.noreply.github.com>
Date: Sun Aug 22 12:26:02 2021 +0800

Update README.md

commit 7a2612b3ae1e6fd6824781d3dd921608adb6a619
Author: xiong <68106285+xiongzhuozhuo@users.noreply.github.com>
Date: Sun Aug 22 12:16:09 2021 +0800

Create README.md

commit a1431ae9fc3ef4f2ddd35c6a44349b69a5bd2f8b
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 17:10:05 2021 +0800

3rd commit

commit 1928061d327bfa64a0a6ce3f4faa029b8c1ce776
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 16:14:06 2021 +0800

2nd commit

commit 8a44e8c0e81d4766b22777a61f3233d8b14497cc
Author: xiongzhuo <xiongzhuo@outlook.com>
Date: Sat Aug 21 15:37:06 2021 +0800

1st commit

origin/master, origin/HEAD与现在的指向不一样了,因为远程仓库进行了一次提交,现在它超前一次本地提交


一些命令

git branch -a:列出本地和远程所有的分支

1
2
3
4
5
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

git remote -v:fetch与push的远程仓库信息

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git remote -v
origin https://github.com/xiongzhuozhuo/2021-git-demo.git (fetch)
origin https://github.com/xiongzhuozhuo/2021-git-demo.git (push)

git remote show origin:给出远程仓库的的信息

1
2
3
4
5
6
7
8
9
10
11
12
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
Push URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (local out of date)

修改远程仓库的分支

image-20210824100348299

git remote show origin:显示远程仓库信息

1
2
3
4
5
6
7
8
9
10
11
12
13
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
Push URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
HEAD branch: master
Remote branches:
dev new (next fetch will store in remotes/origin)
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (local out of date)

dev new (next fetch will store in remotes/origin):检测到远程仓库有新分支产生,使用fetch来存储信息到remotes/origin(如果不进行同步,本地存储的关于远程仓库的信息就仍然是旧的)

1
2
3
4
5

xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git fetch
From https://github.com/xiongzhuozhuo/2021-git-demo
* [new branch] dev -> origin/dev

再次使用git remote show origin:就会显示dev tracked


删除远程分支

git fetch对于远程分支被删除的情况是不做任何反应的,它只会将远程仓库新增的信息抓取到本地

使用git remote show origin查看远程仓库信息

1
2
3
4
5
6
7
8
9
10
11
12
13
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
Push URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
HEAD branch: master
Remote branches:
master tracked
refs/remotes/origin/dev stale (use 'git remote prune' to remove)
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (local out of date)

refs/remotes/origin/dev stale (use 'git remote prune' to remove):检测到dev是过期的,让用户使用git remote prune去移除这个垃圾对象,实际上也可以通过git fetch --prune进行移除。

使用git fetch --prune时,它会先将本地有而远程没有的进行修剪,然后再进行抓取

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git fetch --prune
From https://github.com/xiongzhuozhuo/2021-git-demo
- [deleted] (none) -> origin/dev

19. git fetch & git pull

1.初始状态

image-20210824104751038

2.远程仓库更新一次提交,本地仓库使用fetch抓取更新

image-20210824105452484

3.执行git merge origin/master,合并分支

image-20210824105849505

4.远程仓库有一次提交,本地仓库在未fetch的情况下更新一次提交,同时进行git fetch 抓取远程仓库

image-20210824110936322

5.执行git merge origin/master

image-20210824111351495

6. 执行git push origin master

image-20210824111542375

git pull可以一次性代替git fetchgit merge origin/master将本地仓库推送到远程仓库

20. FETCH_HEAD与git pull

如果是在某个分支上去执行了git fetch,则排在FETCH_HEAD第一行的就是当前分支所对应的远程分支所对应的最新一次commit,只要切换分支并运行了git fetch那么FETCH_HEAD里的内容顺序就会改变

验证

  1. 在远程仓库创建新的分支dev

  2. 并在新分支上做一次commit

    image-20210824122743203

  3. git remote show origin查看远程仓库信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ git remote show origin
    * remote origin
    Fetch URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
    Push URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
    HEAD branch: master
    Remote branches:
    dev new (next fetch will store in remotes/origin)
    master tracked
    Local branch configured for 'git pull':
    master merges with remote master
    Local ref configured for 'git push':
    master pushes to master (local out of date)
  4. git fetch拉取远程仓库更新

    1
    2
    3
    4
    5
    6
    7
    8
    9
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ git fetch
    remote: Enumerating objects: 4, done.
    remote: Counting objects: 100% (4/4), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), 660 bytes | 22.00 KiB/s, done.
    From https://github.com/xiongzhuozhuo/2021-git-demo
    * [new branch] dev -> origin/dev
  5. 查看objects文件内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    xiong@SURFACE-PRO6 C:\Files\git-clone\2021-git-demo
    $ tree .git /f
    卷 Local Disk 的文件夹 PATH 列表
    卷序列号为 C0000100 F296:2801
    C:\FILES\GIT-CLONE\2021-GIT-DEMO\.GIT
    │ config
    │ description
    │ FETCH_HEAD #新增
    │ HEAD
    │ index
    │ packed-refs

    ├─hooks
    │ applypatch-msg.sample
    │ commit-msg.sample
    │ fsmonitor-watchman.sample
    │ post-update.sample
    │ pre-applypatch.sample
    │ pre-commit.sample
    │ pre-merge-commit.sample
    │ pre-push.sample
    │ pre-rebase.sample
    │ pre-receive.sample
    │ prepare-commit-msg.sample
    │ push-to-checkout.sample
    │ update.sample

    ├─info
    │ exclude

    ├─logs
    │ │ HEAD
    │ │
    │ └─refs
    │ ├─heads
    │ │ master
    │ │
    │ └─remotes
    │ └─origin
    │ dev #新增
    │ HEAD
    │ master

    ├─objects
    │ ├─1a
    │ │ 4a4bc16d7019273dfacb0060e1cb654e8b4e11
    │ │
    │ ├─27
    │ │ 8dcf612bf8e033a15c9b429adbb32b0a9210b6
    │ │
    │ ├─7c
    │ │ 8ac2f8d82a1eb5f6aaece6629ff11015f91eb4
    │ │
    │ ├─b8
    │ │ db963d8a1508baf093baf5e7f9424d3e384717
    │ │
    │ ├─ba
    │ │ b3f8573c3317c30242494a0f48d1c99d97eabe
    │ │
    │ ├─da
    │ │ 1f73460673c0e876e2995d4a44889d75372bef
    │ │
    │ ├─info
    │ └─pack
    │ pack-531f25c34d918bbf4e84a1004317c263c51a18aa.idx
    │ pack-531f25c34d918bbf4e84a1004317c263c51a18aa.pack

    └─refs
    ├─heads
    │ master

    ├─remotes
    │ └─origin
    │ dev #新增
    │ HEAD
    │ master

    └─tags

    虽然抓取了远程新增的dev分支,但是本地的heads里没有dev分支信息

  6. 查看新增的FETCH_HEAD文件内容

    1
    2
    3
    4
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ cat .git/FETCH_HEAD
    278dcf612bf8e033a15c9b429adbb32b0a9210b6 branch 'master' of https://github.com/xiongzhuozhuo/2021-git-demo
    da1f73460673c0e876e2995d4a44889d75372bef not-for-merge branch 'dev' of https://github.com/xiongzhuozhuo/2021-git-demo
  7. 使用git checkout dev,本地会新建一个dev分支,并与远程的dev分支进行关联

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ git branch -vv
    * master 70795aa [origin/master: behind 1] Update README.md

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ git checkout dev
    Switched to a new branch 'dev'
    Branch 'dev' set up to track remote branch 'dev' from 'origin'.

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (dev)
    $ git branch -vv
    * dev da1f734 [origin/dev] Create file3.txt
    master 70795aa [origin/master: behind 1] Update README.md
  8. 查看FETCH_HEAD内容:没有变化

    1
    2
    3
    4
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (dev)
    $ cat .git/FETCH_HEAD
    278dcf612bf8e033a15c9b429adbb32b0a9210b6 branch 'master' of https://github.com/xiongzhuozhuo/2021-git-demo
    da1f73460673c0e876e2995d4a44889d75372bef not-for-merge branch 'dev' of https://github.com/xiongzhuozhuo/2021-git-demo

    但是在当前分支上运行git fetch后,再次查看

    1
    2
    3
    4
    5
    6
    7
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (dev)
    $ git fetch

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (dev)
    $ cat .git/FETCH_HEAD
    da1f73460673c0e876e2995d4a44889d75372bef branch 'dev' of https://github.com/xiongzhuozhuo/2021-git-demo
    278dcf612bf8e033a15c9b429adbb32b0a9210b6 not-for-merge branch 'master' of https://github.com/xiongzhuozhuo/2021-git-demo

    描述得到验证


查看分支状况

此时本地分支和远程分支是同步的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git branch -vv
dev da1f734 [origin/dev] Create file3.txt
* master 278dcf6 [origin/master] Update file1.txt

xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git fetch -v
POST git-upload-pack (154 bytes)
From https://github.com/xiongzhuozhuo/2021-git-demo
= [up to date] master -> origin/master
= [up to date] dev -> origin/dev

xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
Push URL: https://github.com/xiongzhuozhuo/2021-git-demo.git
HEAD branch: master
Remote branches:
dev tracked
master tracked
Local branches configured for 'git pull':
dev merges with remote dev
master merges with remote master
Local refs configured for 'git push':
dev pushes to dev (up to date)
master pushes to master (up to date)

在远程仓库的dev分支添加一次commit,再执行一次git pull拉取远程仓库的更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (dev)
$ git pull -v
POST git-upload-pack (154 bytes)
POST git-upload-pack (268 bytes)
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 640 bytes | 42.00 KiB/s, done.
From https://github.com/xiongzhuozhuo/2021-git-demo
da1f734..53d3f54 dev -> origin/dev
= [up to date] master -> origin/master
Updating da1f734..53d3f54
Fast-forward
file3.txt | 1 +
1 file changed, 1 insertion(+)

执行git pull时等同于先执行git fetch再执行git merge,查看FETCH_HEAD内容,发现出现在首行的正式dev,得到验证

1
2
3
4
xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (dev)
$ cat .git/FETCH_HEAD
53d3f54af87b26dc3d774b6741bcd5bb562a70e6 branch 'dev' of https://github.com/xiongzhuozhuo/2021-git-demo
278dcf612bf8e033a15c9b429adbb32b0a9210b6 not-for-merge branch 'master' of https://github.com/xiongzhuozhuo/2021-git-demo

22. git push

如果本地分支与远程分支已经同步,则可以直接使用git push进行推送,如果本地仓库又有新建的分支,而且没有和远程仓库的分支进行关联,则可以使用`git

验证

  1. 查看本地分支与远程分支的同步情况

    1
    2
    3
    4
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ git branch -vv
    dev 53d3f54 [origin/dev] Update file3.txt
    * master 278dcf6 [origin/master] Update file1.txt
  2. 新建一个本地分支,查看分支关联情况

    1
    2
    3
    4
    5
    6
    7
    8
    9
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (master)
    $ git checkout -b tmp
    Switched to a new branch 'tmp'

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git branch -vv
    dev 53d3f54 [origin/dev] Update file3.txt
    master 278dcf6 [origin/master] Update file1.txt
    * tmp 278dcf6 Update file1.txt

    tmp现在没有远程分支进行关联

  3. 在tmp分支上进行一次提交

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ echo 'tmp' > tmp.txt

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git add tmp
    fatal: pathspec 'tmp' did not match any files

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git add tmp.txt
    warning: LF will be replaced by CRLF in tmp.txt.
    The file will have its original line endings in your working directory

    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git commit -m 'commit from tmp'
    [tmp 11cdb0f] commit from tmp
    1 file changed, 1 insertion(+)
    create mode 100644 tmp.txt

    如果直接git push:当前分支tmp没有上游分支。推送当前分支并将远程分支设置为上游

    1
    2
    3
    4
    5
    6
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git push
    fatal: The current branch tmp has no upstream branch.
    To push the current branch and set the remote as upstream, use

    git push --set-upstream origin tmp

    --set -upstream:进行关联的选项

    先不进行关联,进行测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git push origin tmp
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 271 bytes | 271.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    remote:
    remote: Create a pull request for 'tmp' on GitHub by visiting:
    remote: https://github.com/xiongzhuozhuo/2021-git-demo/pull/new/tmp
    remote:
    To https://github.com/xiongzhuozhuo/2021-git-demo.git
    * [new branch] tmp -> tmp

    查看关联情况

    1
    2
    3
    4
    5
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git branch -vv
    dev 53d3f54 [origin/dev] Update file3.txt
    master 278dcf6 [origin/master] Update file1.txt
    * tmp 11cdb0f commit from tmp

    tmp仍然没有远程分支进行关联,虽然此时远程仓库已经新建有tmp分支

    image-20210824133448921

    删除远程分支,测试git push -u命令

    1
    2
    3
    4
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git push origin -d tmp
    To https://github.com/xiongzhuozhuo/2021-git-demo.git
    - [deleted] tmp

    将本地tmp再推送一遍

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git push -u origin tmp
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 271 bytes | 271.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    remote:
    remote: Create a pull request for 'tmp' on GitHub by visiting:
    remote: https://github.com/xiongzhuozhuo/2021-git-demo/pull/new/tmp
    remote:
    To https://github.com/xiongzhuozhuo/2021-git-demo.git
    * [new branch] tmp -> tmp
    Branch 'tmp' set up to track remote branch 'tmp' from 'origin'.

    查看此时关联情况:拥有了关联

    1
    2
    3
    4
    5
    xiong@Surface-pro6 MINGW64 /c/Files/git-clone/2021-git-demo (tmp)
    $ git branch -vv
    dev 53d3f54 [origin/dev] Update file3.txt
    master 278dcf6 [origin/master] Update file1.txt
    * tmp 11cdb0f [origin/tmp] commit from tmp

    有了关联之后直接使用git push就能进行推送

22. git hook

image-20210824134450124

23. pre-commit钩子

24. git hook和python