Adding Existing Directories from Personal Computer to GitHub Using Terminal

This guide will walk you through the steps of adding your existing directories to GitHub using the terminal.

Prerequisites

Before starting, make sure you have the following:

Enter the GitHub repository URL:

Steps

1. Navigate to the directory you want to add to GitHub using the terminal.

cd /path/to/directory

2. Initialize Git in the directory.

git init

3. Create a new repository on GitHub.

4. Add the remote repository as the origin.

git remote add origin https://github.com/username/repository.git

5. Add all the files to the staging area.

git add --all

6. Commit the changes.

git commit -m "First commit"

7. Choose the branch.

Here I chose the branch named “main”; some people might use “master”.

git branch -M main

8. Push the changes to GitHub.

git push -u origin main

Note: If your branch name is “master” or something else, change “main” to your branch name.

All Steps


# Initialize Git in the directory.
git init
# Add the remote repository as the origin.
git remote add origin [REPOSITORY_URL]
# Add all the files to the staging area.
git add --all
# Commit the changes.
git commit -m "First commit"
# Choose the branch.
git branch -M main
# Push the changes to GitHub.
git push -u origin main

Un-track Files on Git

If you want to un-track files on Git, use the following command:

git rm --cached filename