Reputation: 351
I have a private repo on GitHub. I have the local workspace of that on my computer.
I have some depo stream in Perforce, that I cloned with "git p4 clone" into a local repo workspace on my computer. The reason is to retain the history from Perforce.
Now I want to push my local repo cloned from Perforce into an existing private repo on GitHub (the one I mentioned at the beginning).
Anyone, can guide me with the steps?
So far I tried:
git p4 clone "my-perforce-stream-path"
then I tried:
git remote add origin "my-private-github-repo-url"
git push -u origin master
I get an error:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'my-private-github-repo-url'
Upvotes: 1
Views: 1038
Reputation: 1067
You first need to pull from the perforce repo into the private github repository. Once you do that, and the github repo is sync up with the perforce one, you're able to push your master branch to the github repo. Follow one of the two alternatives below to get this done:
Alternative 1
Create a local copy of the github repo:
git clone your-github-repo.git
Add a remote:
git remote add p4 "perforce-repo-path"
Pull the changes from the p4
remote into your local:
git pull p4 branch-name
3.1. NOTE: if both repos, github and perforce are not related (meaning they contains unrelated histories to each other) you might end up having an error because git won't let you merge a branch into another from a unrelated repo. You can override that with the --allow-unrelated-histories
option, like this:
git pull p4 branch-name --allow-unrelated-histories
Finally, you should be able to push your local changes to github:
git push -u origin master
Alternative 2
Add the github remote in the perforce repo:
git add remote github url.git
Next, make sure you pull the history of the github remote branch into your local perforce repo (to sync them up before pushing):
git pull github <branch-name> --allow-unrelated-histories
(--allow-unrelated-histories
helps you prevent receiving an error if both repos contain unrelated changes/histories)
Then, push your branch in the perforce repo to the github remote:
git push -u github <branch-name>
NOTE: If you get any issues about the histories, you can use the same --allow-unrelated-histories
flag here.
Upvotes: 1