Mastering Advanced Git Commands

Git is a powerful tool, and knowing some advanced commands can really level up your version control game. In this post, we'll go through some commonly used Git commands along with their purpose, how to use them. 1. git diff Purpose: Show differences between two commits or working directory and index. Command: git diff 2. git log Purpose: Show commit history. Command: git log 3. git clone Purpose: Clone a remote repository to your system. Command: git clone https://github.com/samandersony2003/24MCR087 4. git pull Purpose: Pull changes from remote to local repo. Command: git pull origin main 5. git push Purpose: Push local commits to remote. Command: git push origin main 6. git blame Purpose: Show who last modified each line of a file. Command: git blame ML.txt 7. git merge conflict (not a command) Note: Conflict occurs during a git merge. Here’s how to simulate: git checkout -b new-branch git checkout main git merge new-branch 8. git branch Purpose: List, create, or delete branches. Command: git branch 9. git checkout -b Purpose: Create and switch to a new branch. Command: git checkout –b advanced-git-commands 10 .gitignore Purpose: File to specify untracked files to ignore. Steps: Create .gitignore file in root directory. Add file patterns to ignore. e.g.: *.log node_modules/ No command needed, Git automatically ignores the specified files. Github Repository: Github link: https://github.com/samanderson2003/24MCR087

Apr 26, 2025 - 05:03
 0
Mastering Advanced Git Commands

Git is a powerful tool, and knowing some advanced commands can really level up your version control game. In this post, we'll go through some commonly used Git commands along with their purpose, how to use them.

1. git diff

Purpose: Show differences between two commits or working directory and index.

Command: git diff

2. git log

Purpose: Show commit history.

Command: git log

3. git clone

Purpose: Clone a remote repository to your system.

Command: git clone https://github.com/samandersony2003/24MCR087

Image description

4. git pull

Purpose: Pull changes from remote to local repo.

Command: git pull origin main

5. git push

Purpose: Push local commits to remote.

Command: git push origin main

6. git blame

Purpose: Show who last modified each line of a file.

Command: git blame ML.txt

7. git merge conflict (not a command)

Note: Conflict occurs during a git merge.

Here’s how to simulate:

git checkout -b new-branch

git checkout main

git merge new-branch

8. git branch

Purpose: List, create, or delete branches.

Command: git branch

Image description

9. git checkout -b

Purpose: Create and switch to a new branch.

Command: git checkout –b advanced-git-commands

Image description

10 .gitignore

Purpose: File to specify untracked files to ignore.

Steps:

Create .gitignore file in root directory.
Add file patterns to ignore.

e.g.:

*.log
node_modules/

No command needed, Git automatically ignores the specified files.

Github Repository:
Github link: https://github.com/samanderson2003/24MCR087

Image description