Git & GitHub Essential CLI Reference

Project Setup

1. Initialize Git Repository

git init

Purpose: Creates a local Git repository inside the current project.

Example Generated Structure:

mysite/
├── .git/
├── src/
├── package.json

Run: Once per project


2. Check Repository Status

git status

Purpose: Shows changed, new, and tracked files.

Use: Daily development


First Commit

3. Add Files

git add .

Purpose: Stages all changed files for commit.


4. Create Commit

git commit -m "Initial commit"

Purpose: Saves a snapshot of the project.

Example:

git commit -m "Add homepage"
git commit -m "Update navigation"
git commit -m "Fix footer"

GitHub Connection

5. Create Main Branch

git branch -M main

Purpose: Renames current branch to main.


6. Connect GitHub Repository

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

Purpose: Links local project to GitHub repository.

Run: Once per project


7. Push Project to GitHub

git push -u origin main

Purpose: Uploads project to GitHub.

Run: First push


Daily Workflow

Check Changes

git status

Stage Changes

git add .

Commit Changes

git commit -m "Describe changes"

Push To GitHub

git push

Maintenance

View Commit History

git log --oneline

Purpose: Shows commit history.


Pull Latest Changes

git pull

Purpose: Downloads latest updates from GitHub.

Use:


Common .gitignore

node_modules/
_site/
.env
.DS_Store

Purpose: Prevents unnecessary files from being uploaded.


Daily Workflow

git status
git add .
git commit -m "Update content"
git push

Done.


Important Files & Folders

.git/          → Git repository data
.gitignore     → Ignored files list
package.json   → Project configuration
node_modules/  → Installed packages

Commands Used Most Often

git status
git add .
git commit -m "message"
git push
git pull

Conclusion

For most projects, you'll use only these four commands daily:

git status
git add .
git commit -m "message"
git push

They let you track changes, save progress, and keep GitHub updated.