作为我关于 svn to git migration 后不可用分支的问题的后续,我有一个不同的问题:我无法将新分支推送到我的中央 Git 存储库。
$ git clone ssh://server/opt/git/our_app.git
$ cd our_app
$ git branch my-test-branch
$ git checkout my-test-branch
$ echo test > test.txt
$ git add test.txt
$ git commit test.txt -m "test commit"
[master ed81ec0] test commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 test.txt
$ git push
Everything up-to-date
因此,这不会将我的分支推送到服务器。一位同事建议我查看我的 .git/config,如下所示:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://server/opt/git/our_app.git
[branch "master"]
remote = origin
merge = refs/heads/master
有人建议我手动添加推送条目:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://server/opt/git/our_app.git
push = refs/heads/*:refs/heads/*
现在情况看起来好多了:
$ git push
Password:
Counting objects: 1, done.
Delta compression using up to 1 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (1/1), 5 bytes, done.
Total 1 (delta 1), reused 0 (delta 0)
To ssh://server/opt/git/our_app.git
* [new branch] my-test-branch -> my-test-branch
虽然这行得通,但它仍然感觉像一个黑客。这样做的正确方法是什么?