12 Most Common git Commands YOU MUST KNOW
git init: This command is used to create a new local repository in the current directory. When you initialize a repository with
git init
, Git creates a ‘.git’ subdirectory where it stores the information for the repository. This includes the version history and configuration that Git uses for the repository.git clone: The
git clone
command is used to copy an existing remote repository to your local machine. This is useful when you want to make a local copy of a repository for development, testing, or other purposes.git status: When you run
git status
, Git will show the status of the working directory and the staging area. This is helpful for understanding what changes have been made and what is ready to be committed.git add: The
git add
command is used to add changes in your working directory to the staging area. The staging area is a temporary area where you can prepare your next commit by staging changes for inclusion in the next snapshot.git commit: After staging your changes, you can use
git commit
to record the changes in the staging area as a new snapshot in the local repository. When you commit, you also include a message describing the changes, which is helpful for providing context to your commits.git push: This command is used to upload local changes to the remote repository, typically on a platform like GitHub or GitLab. It’s a way to share your committed changes with others and collaborate on a codebase.
git pull: When you run
git pull
, Git will download the latest commit from a remote repository and merge it with your local branch. This is useful for bringing your local branch up to date with changes that have been made in the remote repository.git branch: The
git branch
command is used to list, create, rename, or delete branches in your local repository. A branch is a pointer to a specific commit, and working with branches allows you to work on separate lines of development.git checkout: Using
git checkout
, you can switch your working directory to a different branch or commit, and it also allows you to discard any uncommitted changes. This is useful for navigating between different parts of a repository.git merge: The
git merge
command is used to combine the changes from one branch into another branch, creating a new commit if there are no conflicts between the branches. This is an essential operation when working with multiple branches in a repository.git diff: With
git diff
, you can see the differences between two commits, branches, files, or the working directory and the staging area. This is helpful for understanding the changes that have been made and reviewing differences in code.git log: The
git log
command is used to show the history of commits in the current branch, along with their message, author, and dates. This is a valuable tool for understanding the evolution of a codebase and reviewing the commit history.