This guide will walk you through the steps of adding your existing directories to GitHub using the terminal.
Before starting, make sure you have the following:
Enter the GitHub repository URL:
cd /path/to/directory
git init
git remote add origin
https://github.com/username/repository.git
git add --all
git commit -m "First commit"
Here I chose the branch named “main”; some people might use “master”.
git branch -M main
git push -u origin main
Note: If your branch name is “master” or something else, change “main” to your branch name.
# 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
If you want to un-track files on Git, use the following command:
git rm --cached filename