Add a local folder to GitHub using the command line
Jun 13, 2018 00:00 · 282 words · 2 minute read
Did you know you can upload almost anything on Github.com?
Recently, I have started uploading many of my files on github, besides code. I do it because I am working on two different computers, one at work and one at home, and I think this is a great way to keep my work synchronized. I am not going to talk more about using github at this point–maybe I will have a dedicated post on that later. In this post, I want to show you how to add a folder on your local computer to github using command line. If you start a project with github from zero, that is easy–read this post. Let’s start by following these 8 steps:
Create an empty repository on github.com. Unless you are a pro, do not create the new repository with README, license, or
gitignore
files, because it will create complications.Open Terminal (Mac/Linux), and change your working directory to your folder on your computer. If you are on windows, you have command prompt.
Initialize the local directory as git repository by typing
git init
in the terminal.Do the routine
git add .
andgit commit -m "first commit"
routine in the terminal.Copy the URL to the empty repository you created in step 1.
Back to the terminal, add the empty repository’s URL to the
git remote add origin *URL_here*
command and run.Still in the terminal, verify the URL with
git remote -v
.Step 4 adds and stages files, and steps 6 and 7 connects the local folder to the repository on github. The last step is to push the staged files to github. In the terminal, run
git push -u origin master
.