Most Common Git Commands

You can easily find GUI to accomplish following operations these days but here are some of the most commonly used Git commands, along with brief explanations and examples:

  1. git init: This command initializes a new Git repository in the current directory. It creates a new .git directory that stores all the information required to track changes in the repository.

Example: $ git init

  1. git clone: This command creates a local copy of a remote Git repository. The repository can be on a remote server or on a local network.

Example: $ git clone https://github.com/user/repo.git

  1. git add: This command adds a file or group of files to the staging area, which is where changes are tracked before being committed to the repository.

Example: $ git add file1.txt file2.txt

  1. git commit: This command records changes to the repository. When you run git commit, you must also provide a message that describes the changes you're committing.

Example: $ git commit -m "Fixed a bug in the code"

  1. git status: This command shows the status of the repository, including any changes that have not yet been staged or committed.

Example: $ git status

  1. git diff: This command shows the differences between the current version of the code and the latest commit.

Example: $ git diff

  1. git log: This command shows a history of all the commits made to the repository.

Example: $ git log

  1. git checkout: This command allows you to switch between different branches or to a specific commit.

Example: $ git checkout master

  1. git branch: This command allows you to create, list, or delete branches.

Example: $ git branch new-feature

  1. git merge: This command combines the changes from one branch into another branch.

Example: $ git merge new-feature

These are some of the most commonly used Git commands, but there are many more available to help you manage your Git repositories.

Leave a Reply

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