how to turn a directory into a git repository code example

Example 1: how to initialize a git repository command line

# New local repository
git init
git add .
git commit -m "Initial commit"

# New remote repository
git remote add origin git@github.com:username/new_repo #ssh
# Now push
git push -u origin master

Example 2: git init repo

git init
git add somefile
git commit -m "initial commit"
git remote add origin https://github.com/username/new_repo
git push -u origin master

Example 3: add github repo

create a new repository on the command line
echo "# {Repo Name}" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/cdcdianne/ReactJS-TheMovieDB.git
git push -u origin main
                
push an existing repository from the command line
git remote add origin https://github.com/cdcdianne/ReactJS-TheMovieDB.git
git branch -M main
git push -u origin main

Example 4: turn a folder into a git repo

$ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME  BRANCH-NAME 
  # Filter the specified branch in your directory and remove empty commits
  > Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
  > Ref 'refs/heads/BRANCH-NAME' was rewritten