[英]How to push an existing local repo into a newly remote one without loosing git history
I have a local git repo with some history. 我有一些历史的本地git回购。
I would like to add it to my remote git server: 我想将其添加到我的远程git服务器中:
# On my server, I create a remote repo
git init project.git --bare --shared
# On my local computer, I add the remote repo
git remote add origin user@server:/srv/git/projet.git
# Try to push
git push origin master
# error: src refspec master does not match any.
# error: failed to push some refs to 'user@server:/srv/git/projet.git'
# Try to pull
git pull origin master
# fatal: Couldn't find remote ref master
# fatal: the remote end hung up unexpectedly
If I clone the remote repo first, then copy the source code, I will lose the git history. 如果我先克隆远程仓库,然后复制源代码,我将丢失git历史记录。
Anyone knows how to do it ? 有人知道该怎么做吗?
I suppose you already manage correctly your repo locally (git add, commit and so on), so this probably doesn't work because on origin (your server) there is no branch master yet, as it is bare and you haven't cloned the repo from the server originally. 我想您已经在本地正确管理了您的仓库(git add,commit等),所以这可能不起作用,因为在源(您的服务器)上还没有分支母版,因为它是裸机并且您尚未克隆最初来自服务器的仓库。
You should try 你应该试试
git push -u origin master
It should push and create the remote master branch as well 它也应该推送并创建远程主分支
From the doc https://git-scm.com/docs/git-push#git-push--u 从文档https://git-scm.com/docs/git-push#git-push--u
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands.
对于每个最新的或成功推送的分支,添加上游(跟踪)引用,该引用由无参数git-pull [1]和其他命令使用。 For more information, see branch..merge in git-config[1].
有关更多信息,请参见git-config [1]中的branch..merge。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.