作为my question about unavailable branches after 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
虽然这有效,但仍然感觉像是黑客。这样做的正确方法是什么?
答案 0 :(得分:4)
要推送新分支,请使用git push origin my-test-branch
答案 1 :(得分:4)
如果您只想使用相同的分支名称推送您的分支,请使用
git push origin my-test-branch
如果您希望更改显示在原始仓库的主分支上:
git push origin my-test-branch:master
答案 2 :(得分:4)
您可以使用
将分支推送到远程存储库 git push origin my-test-branch
然后,您可以使用
查看所有远程分支 git branch -r
Here's an introduction创建/删除远程分支。