What's the equivalent of git clone, using git init, git remote add, git fetch etc.?

元气小坏坏 提交于 2019-12-25 00:22:51

问题


As currently I cannot clone repositories from a Bitbucket server, I've found I can still do a series of git init, git remote add etc. to get the repository on my computer. I would like to make sure I exactly produce the equivalent of a "clone". Is the following correct?

git init
git remote add origin -m master https://www.myserver.com/bitbucket/scm/proj/repo.git
# need to do git fetch twice, otherwise for some reason git branch -r 
# returns "warning: ignoring broken ref refs/remotes/origin/HEAD"
git fetch
git fetch
git branch -r
git checkout --track origin/master
git checkout --track origin/develop
git checkout --track origin/feature/myfeature
# (etc.. for all the branches I need to work with)

I'm also not sure about the flag -m in git remote is needed or potentially harmful.

Some debug info as suggested by @jthill :

Repository 1

git ls-remote --symref origin HEAD
ref: refs/heads/master  HEAD
842163b275ade3ec317543ed3a645f537d719766        HEAD

Repository 2

git ls-remote --symref origin HEAD
ref: refs/heads/master  HEAD
1a1044eef2d46a292305dfc10cf076a4cf1e9933        HEAD

回答1:


That's it. The clone is the init, remote add and fetch part, after that you can e.g. git checkout master even before creating the local ref and git will set it up and auto-track the remote because that sequence is so common. The -m just bypasses what that bitbucket repo has as its own main branch and tells the local git what you want as yours, if master is what you want, it's what you want.

So the -m "should", near as I can figure, avoid whatever misconfiguration is going on with the origin's HEAD, and the second fetch "shouldn't" be necessary. If you'll include the results of git ls-remote --symref origin HEAD it'll probably be possible to identify what's causing the trouble, but I don't see much point, you've got a workaround.



来源:https://stackoverflow.com/questions/54811012/whats-the-equivalent-of-git-clone-using-git-init-git-remote-add-git-fetch-et

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!