0

昨日、私は github リポジトリを作成しましたが、今日、アドバイザーも github リポジトリを作成していることがわかりました。大規模に台無しにすることなく、私のリポジトリを彼のリポジトリに追加する最良の方法は何ですか? 私は過去に物事を大規模に台無しにしてしまったので、確認したいだけです. また、別の StackOverflow 投稿の指示に従おうとして、すでに失敗している可能性があります。

現在、2 つのブランチがあるようです。「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

リポジトリとブランチを混同しているようです。

現在、2 つのブランチがあるようです。「git checkout master」と入力するとファイルが表示され、「git checkout tmp_branch」と入力すると彼のファイルが表示されます。

あなたのコメントが正しければ、実際には別々のリポジトリを持っているわけではなく、同じリポジトリに別々のブランチを持っているだけです。これにより、これを非常に簡単に修正できます。自分のブランチを彼のブランチにマージしてから、彼のブランチで作業を続けたい場合は、次のようにします。

git checkout tmp_branch
git merge origin master

それだけです!:-)

ただし、彼と同じブランチで作業したくない場合があることもここで言及する価値があります。文字通りまったく同じタスクに取り組んでいる場合、それはあなたがやりたいことかもしれませんが、通常、開発者は別々のタスクに取り組んでいます。たとえば、あなたがユーザー認証に取り組んでいて、上司が管理者向けの機能の追加に取り組んでいる場合、おそらく「admin」などと呼ばれるブランチに上司を配置し、 「user-auth」と呼ばれるブランチに配置することができます。 .


申し訳ありませんが、別のメモ - 通常、開発者のチームと一緒に何かに取り組んでいるとき、マスターブランチで直接作業することはありません。独自のブランチで開発を行い、新しいコードがテストされて機能している場合にのみ、それを master ブランチにマージして本番環境にデプロイすることをお勧めします。参考までに:-)。

于 2014-10-27T03:29:38.570 に答える