Git Reference

I’ve been using git for years now but there are commands I use every day while others, not so much.

New Repository

Create a new repository on GitHub at Then locally, run:

echo "# anything" >>
git init
git add
git commit -m "first commit"
git branch -M main
git remote add origin<your-gh-username>/<repository-name>
git push -u origin main

Removing something from git

Because I forgot my .gitignore and the node_modules directory got committed again. Create the .gitignore file this time and run:

git rm -r --cached node_modules
git commit -am "Removed node_modules directory"

Committing a modified file in a submodule

cd inside the submodule directory then add and commit to git from there. You can then go to your project directory and add and commit to git as normal.