修复 error: src refspec 'branch' does not match any

这种情况分为两种:

  • 更改了分支名称
  • push 新的分支到存储库

我遇到的是第二种,下面说一下我的解决方法:

1
2
3
4
5
6
7
# 改成默认分支然后pull一下
git branch -M master
git pull origin master --rebase
# 改回之前的分支名称
git branch -M branch
# Success!
git push origin branch

git log对比:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
commit 9f034779e154d3b3ddb5bc6e98fd645a3ff49dc5 (HEAD -> branch)
Author: Guest <admin@example.com>
Date:   Sun Nov 26 10:47:11 2023 +0800

    commit

commit db2b7d8bec14537869dd07f2bb776522698b346c
Author: Guest <admin@example.com>
Date:   Sun Nov 26 10:46:21 2023 +0800

    fix

commit 2faa39db9015ca47693efbdc59317b1c6fefa4c3 (origin/master, origin/HEAD)
Author: Bob <example@example.com>
Date:   Sun Nov 26 00:25:46 2023 +0000

    feat
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
commit 9f034779e154d3b3ddb5bc6e98fd645a3ff49dc5 (HEAD -> branch, origin/branch)
Author: Guest <admin@example.com>
Date:   Sun Nov 26 10:47:11 2023 +0800

    commit

commit db2b7d8bec14537869dd07f2bb776522698b346c
Author: Guest <admin@example.com>
Date:   Sun Nov 26 10:46:21 2023 +0800

    fix

commit 2faa39db9015ca47693efbdc59317b1c6fefa4c3 (origin/master, origin/HEAD)
Author: Bob <example@example.com>
Date:   Sun Nov 26 00:25:46 2023 +0000

    feat
updatedupdated2023-11-262023-11-26
加载评论