Ninja Space Content Tech Blog

Adding Existing Local Directory to a New GitHub Repo

Posted by Ninja Space Content on Wednesday, December 30, 2020 Under: tech issues
This week seems like a GitHub week for me. Managing files, looking up terminal commands to get my files properly backed up and remembering it all are taking me hours this morning.

I've successfully cloned my old repo earlier today using my two-factor authentication and right now, I've just created another new repo to back up an older jQuery project that I had built months ago. I ran into a couple of issues getting my jQuery project onto GitHub but after some digging, I got it up there now. I didn't originally do a git init for this when I was working on this project because I hadn't learned it yet. Now that I've graduated from my coding bootcamp, I am going back and making sure I have these files on GitHub. Here were my steps below.

(It didn't ask me for a password or token this time like my clone project had asked me due to two-factor authentication so that's one less step I had to make for this one! You can read more about this two-factor authentication that I had to do.)

First, I created a new repository on GitHub on their website and then copied the file name by clicking on the green "Code" button. 
Then, I went into my local file where my jQuery project files are and cloned it with the following in the terminal:
git clone http://github.com(my New GitHub file name).git

Then, I needed to get this local directory to git so I did a git init command in the terminal with this:
git init

Then I tried to add all of my files to git by typing:
git add .
but it was giving all sorts of errors and by googling it, someone said they had to add the files one by one so I had to do that. For example:
git add app.js (hit enter)
git add index.html (hit enter)

and so forth. Then, when I typed git status those files showed up green now so by adding individual files one by one, it worked!

So then, I committed it with:
git commit -m 'my message'

And then typed git push and it provided me an upstream command that I copied and pasted and now my jQuery files are up on GitHub. Yay!

Github Repository Instructions Using Main Branch (2023 Update)

A lot of things has changed since I started coding bootcamp in June 2020 and today. Github no longer defaults to 'master' branch when you are push your files to your repository. I had to learn to make some adjustments and push my old notes away. First off, make sure you initialize before you can follow the steps from Github by entering git init in terminal. Then, you can add the below commands.

  • In the command line, I write: git remote add origin https://github.com/your-github-username/repo-name.git and after I do this, I created a new branch in VSC and named it 'main'.
  • After I am in my 'main' branch, I typed the following command: git branch -M main
  • Last, I type the following to commend to push my files to the GitHub repository: git push -u origin main

Starting my project with npm and react and installing packages

Since I use node with react, I always have to remind myself that I should initialize before installing packages. Remember to initialize with npm init and create your .gitignore file with node modules listed before installing packages. 

As of 2023, create-react-app is no more so I have to start learning Next.js.

In : tech issues 


Tags: git hub  github adding a new repo  git status  git push 

About Ninja Space Content


Ninja Space Content I have been building simple websites on my own since 2008 and currently run several websites at the moment, including this one. I used to be an account manager for an affiliate/e-commerce company, helping affiliates grow their sales so I have some knowledge on the business side and client side of affiliate marketing. Most recently, I decided to complete a JavaScript coding bootcamp and graduated in Dec 2020.
Note: links to resources and promoting special deals may allow me to earn a small commission from each sale.