为什么在将新分支推送到我的Git存储库时遇到问题?

neu*_*242 5 git branch git-push git-clone

作为我在svn到git迁移后关于不可用分支的问题的后续跟踪,我有一个不同的问题:我无法将新分支推送到我的中央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
Run Code Online (Sandbox Code Playgroud)

所以,这不会将我的分支推送到服务器.一位同事建议我查看我的.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
Run Code Online (Sandbox Code Playgroud)

我被建议手动添加推送条目:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ssh://server/opt/git/our_app.git
    push = refs/heads/*:refs/heads/*
Run Code Online (Sandbox Code Playgroud)

事情看起来更好:

$ 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
Run Code Online (Sandbox Code Playgroud)

虽然这有效,但它仍然像一个黑客.这样做的正确方法是什么?

aby*_*byx 4

要推送新分支,请使用git push origin my-test-branch