5

作为我关于 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

虽然这行得通,但它仍然感觉像一个黑客。这样做的正确方法是什么?

4

3 回答 3

4

推送一个新的分支使用git push origin my-test-branch

于 2010-10-25T07:58:02.827 回答
4

如果您只想使用相同的分支名称推送您的分支,那么只需使用

git push origin my-test-branch

如果您希望您的更改出现在原始存储库的主分支上:

git push origin my-test-branch:master
于 2010-10-25T08:01:25.210 回答
4

您可以将分支推送到远程存储库

git push origin my-test-branch

然后,您可以查看所有远程分支

git branch -r

Here's an introduction to creating/removing remote branches.

于 2010-10-25T08:03:01.380 回答