Import existing source code into GitHub

I’ve been creating React apps based on the create-react-app and adding them to my Github account. create-react-app generates many files in the project folder and I wanted to add this to a new Github repo. Originally, I “cheated” by renaming folders locally after I cloned my remote repo. But I wanted to find a cleaner way to import existing source code to Github so here’s what I came up with:


  1. generated the local files to be imported into Github. In my case, it was running create-react-app to generate a React starter project.
  2. git init – Git initialize the local folder
  3. create new repo in Github – I created mine with a as well as a license file. The problem was that create-react-app also createded a file so this would create a conflict.
  4. git remote add origin – to set the remote repo URL locally. Alternatively you can use a Git GUI like SourceTree (under Settings -> Remotes).
  5. rename any local files that are the same as the remote repo. In my case, I had a in both my local and remote repos, which cause a pull error. So I had to rename my local to something else (e.g. before doing a git pull. The error I was getting was:
    • The following untracked working tree files would be overwritten by merge: Please move or remove them before you merge.
  6. git pull origin master – pull the change from the remote repo to the local one.
  7. Delete / update any common files between the remote rand local repositories. In my case, I deleted the pulled locally and replaced it with the auto generated one (that create-react-app generated). I just added a title at the top.
  8. git add -A (stages all files)
  9. git commit -m “initial local commit” (commits to local repo)
  10. git push -u origin master (push to Github)

Further Resources

Import existing source code to GitHub (Stack Overflow)

Git says local branch is behind remote branch, but it’s not (Stack Overflow)