0

昨天我创建了一个 github 存储库,今天我发现我的顾问也创建了一个 github 存储库。将我的存储库添加到他的存储库而不会大量搞砸的最佳方法是什么?我过去把事情搞砸了,所以我只想确定一下。此外,我可能已经通过尝试按照另一个 StackOverflow 帖子上的说明搞砸了。

现在好像我有两个分支,输入“git checkout master”给我我的文件,而输入“git checkout tmp_branch”给我他的文件。我想将我所有的文件添加到他的存储库中并从现在开始使用那个,也许删除我的存储库。

到目前为止,我试图做的是

me@server:~/rootdir$ git remote add origin https://github.com/him/his_repo.git
fatal: remote origin already exists.
me@server:~/rootdir$ git remote add his_repo https://github.com/him/his_repo.git
me@server:~/rootdir$ git push -u his_repo master
Username for 'https://github.com': me@gmail.com
Password for 'https://me@gmail.com@github.com':
To https://github.com/him/his_repo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/him/his_repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
me@server:~/rootdir$ git pull his_repo
Username for 'https://github.com': me@gmail.com
Password for 'https://me@gmail.com@github.com':
warning: no common commits
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 13 (delta 0), reused 10 (delta 0)
Unpacking objects: 100% (13/13), done.
From https://github.com/him/his_repo
 * [new branch]      master     -> his_repo/master
You asked to pull from the remote 'his_repo', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
me@server:~/rootdir$ git checkout -b tmp_branch his_repo/master
warning: unable to rmdir mysubdir: Directory not empty
Branch tmp_branch set up to track remote branch master from repo.
Switched to a new branch 'tmp_branch'
me@server:~/rootdir$ git checkout -b origin/master
Switched to a new branch 'origin/master'
me@server:~/rootdir/subdir$ git checkout -b master
fatal: A branch named 'master' already exists.
me@server:~/rootdir/subdir$ git checkout master
Checking out files: 100% (2409/2409), done.
Switched to branch 'master'
me@server:~/rootdir$ git checkout tmp_branch
warning: unable to rmdir mysubdir: Directory not empty
Switched to branch 'tmp_branch'
me@server:~/rootdir$ git mv * tmp_branch/*
fatal: destination 'tmp_branch/*' is not a directory
me@server:~/rootdir$ cd ..
me@server:~/rootdir$ git checkout master
Checking out files: 100% (2409/2409), done.
Switched to branch 'master'
me@server:~/rootdir$ git push -u tmp_branch master
fatal: 'tmp_branch' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
me@server:~/rootdir$ git push -u his_repo master
Username for 'https://github.com': me@gmail.com
Password for 'https://me@gmail.com@github.com':
To https://github.com/him/his_repo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/him/his_repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

非常感谢 :)

4

2 回答 2

1
于 2014-10-26T22:15:44.417 回答
1

听起来您可能会将存储库与分支混淆:

现在好像我有两个分支,输入“git checkout master”给我我的文件,而输入“git checkout tmp_branch”给我他的文件。

如果您的评论是正确的,那么您实际上没有单独的存储库,只是在同一个存储库上的不同分支 - 这使得修复非常容易。如果您想将您的分支合并到他的分支中,然后继续使用他的分支,只需执行以下操作:

git checkout tmp_branch
git merge origin master

这里的所有都是它的!:-)

然而,在这里也值得一提的是,你可能不想和他在同一个分支上工作。如果您实际上是在处理相同的任务,那可能就是您想要做的,但通常开发人员正在处理不同的任务。例如,如果您正在处理用户身份验证,而您的老板正在为管理员添加一些功能,您可能希望他在一个名为“admin”的分支上,而您可能在一个名为“user-auth”的分支上.


抱歉,另一个注意事项 - 通常,当您与开发人员团队一起工作时,您也永远不会直接在分支上工作。最好在您自己的分支上进行开发,并且只有在您的新代码经过测试并且可以正常工作后,然后将其合并到主分支以将其部署到生产中。仅供参考:-)。

于 2014-10-27T03:29:38.570 回答