Essential Git Commands: A Comprehensive List

Git is a powerful version control system that allows developers to manage and track changes in their code efficiently. This comprehensive list includes essential Git commands organized by categories, providing descriptions and examples for each command. Whether you’re a beginner or an experienced developer, this guide will help you navigate Git effectively. Getting & Creating […]
Mohammed Wasim Akram
Blog Post Author
Last Updated: September 6, 2024
Blogpost Type:

Git is a powerful version control system that allows developers to manage and track changes in their code efficiently.

This comprehensive list includes essential Git commands organized by categories, providing descriptions and examples for each command.

Whether you’re a beginner or an experienced developer, this guide will help you navigate Git effectively.

Getting & Creating Projects

  • git init: Initializes a new Git repository in the current directory.
  • Example: git init
  • git clone <repository-url>: Creates a local copy of a remote repository.
  • Example: git clone https://github.com/user/repo.git

Basic Snapshotting

  • git status: Displays the state of the working directory and staging area.
  • Example: git status
  • git add <file>: Adds a specific file to the staging area.
  • Example: git add file.txt
  • git add -A: Stages all changes (new, modified, deleted files).
  • Example: git add -A
  • git commit -m "<message>": Commits the staged changes with a descriptive message.
  • Example: git commit -m "Initial commit"
  • git rm <file>: Removes a file from the working directory and stages the removal.
  • Example: git rm file.txt

Branching & Merging

  • git branch: Lists all local branches.
  • Example: git branch
  • git branch -a: Lists all local and remote branches.
  • Example: git branch -a
  • git branch <branch-name>: Creates a new branch with the specified name.
  • Example: git branch feature-xyz
  • git branch -d <branch-name>: Deletes a local branch that has been merged.
  • Example: git branch -d feature-xyz
  • git branch -D <branch-name>: Forces the deletion of a local branch, regardless of its merge status.
  • Example: git branch -D feature-xyz
  • git push origin --delete <branch-name>: Deletes a branch from the remote repository.
  • Example: git push origin --delete feature-xyz
  • git checkout -b <branch-name>: Creates a new branch and switches to it.
  • Example: git checkout -b feature-xyz
  • git checkout <branch-name>: Switches to the specified branch.
  • Example: git checkout main
  • git merge <branch-name>: Merges the specified branch into the current branch.
  • Example: git merge feature-xyz
  • git stash: Stashes changes in the working directory for later use.
  • Example: git stash
  • git stash pop: Applies the stashed changes back to the working directory.
  • Example: git stash pop

Sharing & Updating Projects

  • git push origin <branch-name>: Pushes the specified branch to the remote repository.
  • Example: git push origin main
  • git push -u origin <branch-name>: Pushes changes and sets the upstream branch.
  • Example: git push -u origin feature-xyz
  • git pull: Fetches and merges changes from the remote repository to the current branch.
  • Example: git pull
  • git remote add <name> <url>: Adds a new remote repository.
  • Example: git remote add origin https://github.com/user/repo.git
  • git remote set-url origin <url>: Changes the URL of an existing remote repository.
  • Example: git remote set-url origin https://github.com/user/new-repo.git

Inspection & Comparison

  • git log: Shows the commit history for the current branch.
  • Example: git log
  • git log --oneline: Displays a simplified commit history.
  • Example: git log --oneline
  • git diff <source> <target>: Shows differences between two branches or commits.
  • Example: git diff main feature-xyz

Configuration

  • git config --global user.name "<name>": Sets the global username for commits.
  • Example: git config --global user.name "John Doe"
  • git config --global user.email "<email>": Sets the global email for commits.
  • Example: git config --global user.email "[email protected]"

Conclusion

This comprehensive list of Git commands provides a solid foundation for managing your projects effectively.

By familiarizing yourself with these commands, you can streamline your workflow, collaborate with others, and maintain a clean and organized codebase.

Whether you’re initializing a new repository, managing branches, or pushing changes to a remote repository, these commands will help you navigate Git with confidence.

If you have any further questions or need additional commands, feel free to ask!

0 Shares
Services Page Hero Image - SyncWin

Join SyncWin Community

SyncWin Community is the ultimate platform for anyone looking to find their way to success in Online Business Development & Webpreneurship. This community ​is the best place for those who wish to Learn, Grow, and Network with other Like-Minded Digital Entrepreneurs & Business Owners.
Free Membership
Article Author
Mohammed Wasim Akram
Hello myself Wasim, I’m from the city of Mother Teresa Calcutta (currently Kolkata), which exists in India, a country of unity in diversity.I belong to the sales and marketing field with 10+ years of experience. In December of 2017, I switched my career from a 9 to 5 traditional job to the digital entrepreneurship.Currently, I am a Google and HubSpot certified Digital Marketer, a WordPress Specialist, Web Designer & Strategist and the founder of SyncWin.
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
LET'S WORK TOGETHER!

Explore Our Digital Services

Get a head start with our expertly crafted ready-made services to save time and effort by hiring us to handle the heavy lifting for you and unlock the full potential of your online business.
Learn More
No Credit Card Required!
SyncWin Logo
SyncWin is a dedicated place to explore the Content, Discussions, & Useful Details around topics like Business, Technology, and Lifestyle to help you learn and grow in your life.
About Us
Made with ❤ for WinSyncers
Copyright © 2018 - 2024 by SyncWin | All Rights Reserved.
crossmenuarrow-right
0 Shares
Copy link