Home > Enterprise >  How to make a new GitHub repo of the local with same commit history?
How to make a new GitHub repo of the local with same commit history?

Time:03-25

I am a newbie to Git and GitHub. I know the basic cloning, pushing, and merging. I want to be good at Git so I decided to track my code using Git.

I made a local repo of my code. I have done 3 commits until now. I created a new repo on GitHub and tried to push the changes but they won't merge because of the different commit history, I don't want to complicate things so, I deleted the repo on Github.

I want to push my local repo with all the commits to a new remote in Github. Is there any way to do it?

CodePudding user response:

but they won't merge because of the different commit history

I guess, you have chosen any of the checkboxes while creating a repository in GitHub: Initialize this repository with a README or .gitignore or license

This will make your remote repository NOT empty, with files / commits not exist in your local repository. That is when the "different commit history" generated.

For solution, you should

  1. create a repository WITHOUT any ticks in this picture
  2. Or, if your remote repository has nothing important, you can OVERWRITE it with -f parameter for git push, for example git push -f origin master or something equivalent.
  • Related