Here's a super simple tutorial for beginners. So simple that it's essentially exactly what GitHub posts on its site to help people out with this exact situation. I merely added three lines of commands to fill in some unfortunate gaps.
Scenario
You have a repo on your computer with all the code you need for your project. It works great. The only downside? It doesn't have any version control. As in, it ain't a Git repo. As a result, it also isn't shared anywhere (e.g., GitHub). You want to fix this, but how?
If you log in to your GitHub account and create a new repo, it gives you three different options for building out your shiny new remote repo. The second option makes the most sense for this scenario: "…or push an existing repository from the command line." You do have an existing repo, and you do love the command line. However, if you merely cd
into your existing repo and run the three commands that GitHub provides, you'll quickly see that you actually need do a few more steps to accomplish your goal.
Solution
Here's my full guide to Git-ifying an existing repo and migrating it to GitHub.
After logging in to your GitHub account and creating a new repo, go back to your Terminal app and cd
into your local repo. Then:
git init
git remote add origin https://github.com/<YOURUSERNAME>/<YOURREPONAME>.git
git branch -M main
git add .
git commit -m "Add initial files from local"
git push -u origin main
Note that steps 2, 3, and 5 are verbatim from GitHub's recommendations. While my three "missing steps" may seem painfully obvious to any experienced developer, I wanted to highlight them for the more junior members among us.
Top comments (0)