-1

I was given access to a GitHub repository that doesn’t belong to me.

My goal: I want to clone this repo into my own new GitHub repository and then push it there.

I’ve already cloned the repo locally, but when I try to push it to my own remote (origin), I get this error:

Updates were rejected because the tip of your current branch is behind its remote counterpart. If you want to integrate the remote changes 

I’m not sure how Git works in this case when dealing with someone else’s repo.

I even tried manually copying the files into my new repository, but that felt really messy.

What’s the correct way to do this?

Yes i can just fork the repo. But I dont want to create any link the original one.

2
  • 1
    If you are sure you want to push the branch as-is into the new repo, just force-push. You probably crated the repo with a commit with the readme or something, so you can't just push. It needs to use --force. Commented Sep 27 at 20:45
  • Its a repo provided by the teacher, I don't wanna fork it but i want to inject all of the repo's file into mine. Commented Sep 27 at 20:51

1 Answer 1

2

Do you also want to copy the .git history to be copied to your new repo or only the code files?

I suppose u want to you to copy the .git history too( tags, branches, commits) , use --bare flag while cloning to get just the .git history and then use the --mirror flag while pushing to the new repo which also regenerates the code files:

git clone --bare https://github.com/owner/repo1.git cd repo1.git git push --mirror https://github.com/you/repo2.git 
Sign up to request clarification or add additional context in comments.

1 Comment

That work's like charm! I thought LLM's have enough sense to figure it out, but I was wrong.(or i am noob)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.