Welcome to our comprehensive Git Commands Cheatsheet! This guide is designed to help both beginners and intermediates understand and master essential Git commands. Let's dive in! 📝
Git is a powerful version control system that helps developers track changes in their codebase, collaborate effectively, and manage projects efficiently. It's essential for any developer looking to work on complex projects or contribute to open-source projects.
Creates a new Git repository in your current directory.
$ git initStages a file for the next commit. You can also use git add . to stage all changes.
$ git add index.htmlCreates a new commit with the given message.
$ git commit -m "Added index.html"Shows the current state of your repository, including untracked, modified, and staged files.
$ git statusDisplays the commit history for your repository.
$ git logBranching allows you to work on different features or bug fixes without affecting the main codebase. Here are some essential branching commands:
Creates a new branch.
$ git branch feature-branchSwitches to a different branch.
$ git checkout feature-branchMerges the specified branch into the current branch.
$ git checkout main
$ git merge feature-branchStashes changes that aren't yet committed, allowing you to switch branches or work on something else temporarily.
$ git stashReverts changes made in a specific commit.
$ git revert <commit_hash>Pulls the latest changes from the remote repository.
$ git pull origin mainWhat does `git init` do?
How do you switch to a different branch?
What does `git pull` do?