I'm developing a personal project that wasn't originally intended to be public (just for me, testing, fun, learning, etc.) This project has grown a bit and become serious enough that I now want to make it public and contributable on GitHub.

So I'd like to set up Git for this project, but I don't know the right approach to take. My naive approach would be to start a new Git environment, push the whole project into the master branch and then continue to develop the project using Git as if it had been there all along. It doesn't seem a very elegant solution to me, though.

I don't know much about Git other than the basics, so which approach would be considered the more appropriate?

  • 73
    Aside from your main question: use source control for every project, not just ones you intend to make public. At some point, you will want to go back to a previous version or one of the many other things a VCS enables. Commented Jun 3 at 16:38
  • 9
    On top of the point of wanting history or other VCS features, following the suggestion from @PhilipKendall also means that you will get in the habit of working with VCS, which will make it much easier to actually do complicated things with it when you need to. Commented Jun 4 at 0:31
  • 7
    Make sure you do not commit any credentials! Credential leaks are quite common through GitHub. Commented Jun 4 at 5:36
  • 2
    @foxy as someone who has had to use Version Control (other stuff exists that isn't Git) for all my jobs (12 years a programmer), I'd recommend learning it and using it for everything lol. Good luck on the journey and hopefully you realize how powerful git is as simply change tracking - and how it's worth using for that reason alone... as you also learn how important it is in the stack of other tools that rely on Git.
    – WernerCD
    Commented Jun 4 at 12:36
  • 8
    "use source control for every project" - And one more aside: you don't even have to use a remote repository. You can use git completely local, you basically do all the same things, but never push. This gives you the advantages of a version history, without anything ever leaving your computer. And it's relatively trivial to migrate this to a remote repository if you ever choose to.
    – marcelm
    Commented Jun 4 at 16:17

4 Answers 4


My naive approach would be to start a new Git environment, push the whole project into the master branch and then continue to develop the project using Git as if it had been there all along.

That seems like a perfectly good approach. If you don't have the history of what you've done so far in any convenient form then you can't get that history into Git. If you have some old versions, but not tracked as any systematic series of versions, then it's unlikely to be worthwhile converting that series of ad-hoc versions into a Git history.

So probably the best thing is to just add all files that make up the current version of the project (excluding anything that needs to be kept secret) to a Git repository and then use Git to track changes from now on.

  • 3
    Yup, this is it. Treat what you've done so far as a proof of concept. Now you have something viable, so it's worth putting in version control. Moving forward, history is important. Not so much before you've determined this is viable. Commented Jun 3 at 17:14
  • 44
    Please be sure to remove any private data (like auth keys) from the source before pushing it to Github or wherever. Commented Jun 4 at 1:20
  • 3
    It's probably worth noting this is exactly what happens if you clone a template repo or use a project starter scaffold. Commented Jun 4 at 13:47
  • 10
    @GregBurghardt I endorse this answer, but not your comment about past history being unimportant. Past history is lost already, and not salvageable with reasonable effort. It's gone. Stop the ongoing loss and move on. Commented Jun 4 at 16:42
  • 4
    To slightly correct this, commit all source files and project/make files only. Do not commit any compiled files, intermediate files, auto-generated files, or anything like this. A good rule of thumb is that if you didn't directly create it yourself, it probably shouldn't be in your VCS. (I've seen too many people just commit everything, and then I've had to clean up all the OBJs and everything.)
    – Graham
    Commented Jun 6 at 0:54

I've done this a couple times. What I usually do (if using Github) is create a new empty repo on Github, clone it locally, copy my code into it, and push it all up.

  • 41
    You can actually just git init in your project folder, and git remote add origin [link] and then push. In fact you don't even need a remote to work with git. You can just git init and do everything you want there
    – inaba
    Commented Jun 4 at 8:15
  • 18
    @inaba That's an excellent point and it addresses the OP's first paragraph ("I wasn't using git because this project wasn't meant to be public"). Github is just one particular service provider that relies on git, but git can be used without github; and even github has the option for both private and public repositories. In general, version control is useful even if a project isn't meant to be public.
    – Stef
    Commented Jun 4 at 10:03
  • 4
    @Stef Heck OP can just make another folder on his PC and have that as their remote!
    – inaba
    Commented Jun 4 at 10:50
  • @Stef not only that, but github offers private git hosting for free. Arguably unnecessary if you're not collaborating, you can just use git on your computer combined with a general purpose PC backup tool in case the computer breaks or you accidentally erase something permanently within the repository.
    – bdsl
    Commented Jun 4 at 17:10
  • 3
    @inaba Yes, that was one of the most critical things Git provided... a source control system which could work both with and without a remote repo server. Prior to Git (and to the other distributed systems that have mostly disappeared now), it was either-or... you used a local system (e.g. RCS) or a server-based system (CVS, SVN), and moving from the former to the latter was an often-painful migration exercise. Commented Jun 4 at 22:33

If you were doing any sort of release management, for example, a ZIP file, any time you made changes, you could incrementally put the contents of each into Git, starting with the oldest, or if you had a regular backup of the code being made, you could restore a backup for each day's work and put the contents of each into Git, starting with the oldest.


You didn't say what your desktop environment is, although it might not matter. I've had the same issue and approached it a few different ways. In my case, I am working on a Windows desktop and using GitHub.

In all cases, the first step is to create the new repository on the server.

I have cloned to a new folder, copied my work into that folder and then discarded the original working folder once everything was under source control.

I have also cloned to a temporary folder and copied the .git into my working folder (discarding the temp folder).

I think you might be able to clone an empty repo onto an existing folder, but there are probably safeguards that will disallow it lest your work be overwritten.

I think you can also create a new repo in your working folder which will be initially detached from any remotes. The next step would then be to add your GitHub repo as a new remote.

  • 2
    Check out this comment from two days ago: softwareengineering.stackexchange.com/questions/453584/… -- In short, don't clone the repo and copy your files into it, turn your existing development tree into a git repo, add the GitHub repo as remote, and push. GitHub actually has instructions on how to do this when you create a new repo there. Commented Jun 6 at 15:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.