Git and GitHub Commands

Git Setup: Configuring User Information Across All Repositories

1. Set Your Username

🔹 git config --global user.name "Your Name"

$ git config --global user.name "John Doe"

2. Set Your Email Address

🔹 git config --global user.email "[valid-email]"

$ git config --global user.email "johndoe@example.com"

3. Check Your Configuration

🔹 git config --global --list

$ git config --global --list

4. Update or Remove Configuration (if needed)

$ git config --global --replace-all user.name "Jane Doe"

$ git config --global --replace-all user.email "janedoe@example.com"

5. Remove User Configuration

$ git config --global --unset-all user.name

$ git config --global --unset-all user.email

Git Essentials: Initialize,Clone, Set Up Remote, and Push Changes

1. Initialize a New Repository

🔹 Navigate to Your Project Directory

$ cd /path/to/your/project

🔹 Initialize the Repository

$ git init

🔹 Add All Files to the Staging Area

$ git add .

🔹 Commit the Initial Set of Files

$ git commit -m "Initial commit"

2. Clone an Existing Repository

🔹 Clone a Repository

$ git clone github.com/username/repository-name.git

🔹 Navigate into the Cloned Repository

$ cd repository-name

3. Set Up Remote Repository

🔹 Add a Remote Repository

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

🔹 Verify the Remote URL

$ git remote -v

4. Push Changes to GitHub

🔹 Push Changes to the Remote Repository

$ git push -u origin main

1. Checking Status of Your Files

🔹 git status

$ git status

2. Adding Files to Staging Area

🔹 git add [file]

$ git add index.html

3. Unstaging Files

🔹 git reset [file]

$ git reset index.html

4. Viewing Unstaged Changes

🔹 git diff

$ git diff

5. Viewing Staged Changes

🔹 git diff --staged

$ git diff --staged

6. Committing Your Changes

🔹 git commit -m “[descriptive message]”

$ git commit -m "Add new feature to the homepage"

Git Branching & Merging:-

1. Listing Branches

🔹 git branch

$ git branch

2. Creating a New Branch

🔹 git branch [branch-name]

$ git branch feature-new-design

3. Switching Between Branches

🔹 git checkout [branch-name]

$ git checkout feature-new-design

4. Merging Branches

🔹 git merge [branch-name]

$ git merge feature-new-design

5. Viewing Commit History

🔹 git log

$ git log

Git Share & Update: Keep Your Repositories in Sync

1. Adding a Remote Repository

🔹 git remote add [alias] [url]

$ git remote add origin https://github.com/username/repo.git

2. Fetching Branches from a Remote Repository

🔹 git fetch [alias]

$ git fetch origin

3. Merging a Remote Branch into Your Local Branch

🔹 git merge [alias]/[branch]

$ git merge origin/main

4. Pushing Local Commits to a Remote Repository

🔹 git push [alias] [branch]

$ git push origin main

5. Pulling and Merging Updates from a Remote Repository

🔹 git pull

$ git pull

Git Tracking: Handling File Removals and Path Changes

**1. Removing a File from the Project
**🔹 Delete the File and Stage the Removal

$ git rm [file]

Example:

$ git rm old-file.txt

2. Moving or Renaming a File

🔹 Change an Existing File Path and Stage the Move

$ git mv [existing-path] [new-path]

Example: $ git mv docs/old-name.txt docs/new-name.txt

3. Viewing Path Changes in Commit Logs

🔹 Show Commit Logs with Path Movement Indications

$ git log --stat -M

example:$ git log --stat -M