
26/06/2025
π Summary
β
git init = Initialize a Git repo..
β
git add README.md = Stage a file.
β
git commit -m "first commit = Commit the file.
β
git branch -M main = Rename the default branch to `main`.
β
git remote add origin = Connect the local repo to GitHub.
β
git push -u origin main = Push the code to GitHub.
Here's a step-by-step explanation:
β git init
Purpose: Initializes a new Git repository in the current directory.
What it does?
Creates a hidden `.git` folder in your project directory,
Setup the directory for tracking changes with Git.
---
β git add README.md.
Purpose: Stages the `README.md` file for commit.
What it does?
Adds `README.md` to the **staging area** (a temporary area where changes are prepared for committing).
Only changes in the staging area are included in the next commit.
β git commit -m "first commit"
Purpose: Creates a commit with the staged changes.
What it does:
- Takes all staged changes and saves them permanently in the Git history.
- The `-m` flag lets you add a commit message. "this is message body"
β git branch -M main.
Purpose: Renames the default branch from `master` to `main`.
What it does:
- Git traditionally used `master` as the default branch name, but many projects now use `main`.
- `-M` forcefully renames the branch (in case a `master` branch already exists).
β git remote add origin https://github.com/mdabdulhalim-bd/JavaScript-DOM.git`
Purpose: Links your local repository to a remote repository on GitHub.
What it does:
- Adds a remote named `origin` pointing to your GitHub repo's URL.
β git push -u origin main.
Purpose: Pushes your local commits to the remote repository (GitHub).
What it does:
Uploads the `main` branch and its commits to the remote (`origin`).
- The `-u` flag sets `origin/main` as the **upstream branch**, meaning future `git push` or `git pull` commands will default to `origin/main`.