Git Essentials: Mastering Initial Commands for Effective Version Control

Git is an essential tool for version control, allowing developers to track and manage changes to code over time. Understanding the initial commands in Git is crucial for effective software development. This guide provides an overview of basic Git commands and their functions.

Basic Git Configuration Commands

  • Check Git Version: git --version
  • Set Global Username: git config --global "Your Name"
  • Set Global Email: git config --global "[email protected]"
  • List Configuration: git config --list (press ‘q’ to exit command pause)
  • Set Default Editor to Emacs: git config --global core.editor emacs
  • Set Default Editor to Vim: git config --global core.editor vim
  • View Configured Username: git config
  • View Configured Email: git config

Repository and Staging Area Commands

  • Check Status: git status
  • Initialize Repository: git init
  • Add Files to Staging: git add --all or git add "FileName"

Commit and Log Commands

  • Commit Changes: git commit -m "Commit message"
  • View Commit History: git log

Restoration and Deletion Commands

  • Unstage File: git restore --staged "FileName"
  • Restore Older Version: git restore "FileName"
  • Unstage File (Alternate): git rm --cached FileName
  • Discard Working Directory Changes: git restore FileName
  • Delete Git Repository: rm -rf .git

Branching in Git

  • Create New Branch: git checkout -b BranchName
  • List Branches: git branch
  • List Branches with Verbose: git branch -v
  • List Merged Branches: git branch --merged
  • List Non-Merged Branches: git branch --no-merged
  • Delete Branch: git branch -d BranchName
  • Force Delete Branch: git branch -D BranchName

Additional Useful Git Commands

  • List Files: ls
  • Print Working Directory: pwd
  • Create Empty File: touch
  • List Files with Details: ls -lah
  • Open Nano Editor: nano
  • Exit Screen: Press ‘q’
  • Detailed Commit History: git log -p
  • Commit History with Limit: git log -p -N
  • Commit History with Stat: git log --stat
  • One-Line Log Format: git log --pretty=oneline
  • Amend Last Commit: git commit --amend
  • Force Checkout: git checkout -f
  • Add and Commit in One Step: git commit -a -m "message"
  • Push Local to Remote: git push origin localBranchName:RemoteBranchName
  • Delete Remote Branch: git push -d origin BranchName

Frequently Asked Questions

  • Can I restore deleted branches? Yes, but it requires specific steps.
  • Is it safe to amend commits? Amending should be done carefully, especially for shared repositories.


Git is a powerful tool for version control and collaboration. Mastering these initial commands can significantly improve your workflow and efficiency in managing code versions.

Explore more tech insights and tips at Share your experiences and questions in the comments, and don’t forget to share this post with fellow developers!


Leave a Reply

Your email address will not be published. Required fields are marked *