DEV Community

Vaishnavi D
Vaishnavi D

Posted on

Advanced Git commands

1. git diff

Shows changes between working directory and index or between commits.

git diff    

git diff --staged       
git diff HEAD           
Enter fullscreen mode Exit fullscreen mode

2. git log

Displays commit history.

git log       

git log --oneline       
git log --graph         
Enter fullscreen mode Exit fullscreen mode

3. git clone

Clones a repository from remote (e.g., GitHub) to your system.

git clone <repo_url>  


git clone https://github.com/username/project.git
Enter fullscreen mode Exit fullscreen mode

4. git pull

Fetches and merges changes from the remote repository.

git pull origin main   
Enter fullscreen mode Exit fullscreen mode

5. git push

Pushes local commits to the remote repository.

git push origin main   
Enter fullscreen mode Exit fullscreen mode

6. git blame

Shows who made each line change and when.

git blame filename
Enter fullscreen mode Exit fullscreen mode

7. .gitignore

Tells Git to ignore specific files/folders.

Create a .gitignore file in the root of your repo and add patterns:

node_modules/
.env
*.log
/dist
Enter fullscreen mode Exit fullscreen mode

8. git branch

Manages branches in your repo.

git branch               
git branch new-feature   
git checkout new-feature 
Enter fullscreen mode Exit fullscreen mode

9. Git Merge Conflict

Occurs when merging changes and Git can't automatically resolve differences.

Steps:

git checkout main
git pull
git merge feature-branch  

git add .
git commit
Enter fullscreen mode Exit fullscreen mode

10. Git Fork (on GitHub)

Forking creates a personal copy of someone else's repo.

Steps:

  1. Go to a repo on GitHub.
  2. Click Fork (top-right).
  3. Clone your fork:
git clone https://github.com/your-username/forked-repo.git
Enter fullscreen mode Exit fullscreen mode

11. GitHub Wiki

Used for project documentation inside the GitHub repo.

How to Use:

  1. Go to your GitHub repository.
  2. Click on the "Wiki" tab.
  3. Click "Create the first page".
  4. Add pages/sections with Markdown like .md files.

SCREENSHORTS:

Image description

Image description

Top comments (0)