DEV Community

Cover image for Useful git command
Md Mohaymenul Islam (Noyon)
Md Mohaymenul Islam (Noyon)

Posted on

Useful git command

Here's a list of commonly used Git commands along with their usage:

  1. git init: Initializes a new Git repository in the current directory.

  2. git clone <repository>: Clones an existing repository to your local machine.

  3. git add <file>: Adds a file to the staging area, ready to be committed.

  4. git commit -m "<message>": Commits the changes in the staging area with a descriptive message.

  5. git status: Shows the current status of the repository, including any changes that have been made but not yet committed.

  6. git diff: Shows the differences between the current state of the repository and the last commit.

  7. git log: Shows the commit history for the repository.

  8. git branch: Shows the branches in the repository, and which branch you are currently on.

  9. git branch <branch_name>: Creates a new branch with the specified name.

  10. git checkout <branch_name>: Switches to the specified branch.

  11. git merge <branch_name>: Merges the specified branch into the current branch.

  12. git pull: Pulls in any changes from the remote repository to your local repository.

  13. git push: Pushes any local changes to the remote repository.

  14. git stash: Stashes any changes that have not yet been committed, so you can switch to a different branch without losing your work.

  15. git stash apply: Applies any stashed changes to the current branch.

These commands form the foundation for working with Git, and should cover most of your needs for basic version control. However, there are many more advanced Git commands and features, such as rebasing, cherry-picking, and bisecting, that you can explore as you become more proficient with the tool.

Here are some more Git commands that you may find useful:

  1. git rm <file>: Removes a file from the repository.

  2. git mv <file> <new_file>: Renames a file in the repository.

  3. git reset <file>: Unstages a file that has been added to the staging area.

  4. git checkout <commit> <file>: Reverts a file to a specific commit.

  5. git revert <commit>: Creates a new commit that undoes the changes made in a specific commit.

  6. git rebase: Reapplies a series of commits on top of a different base commit.

  7. git cherry-pick <commit>: Applies the changes made in a specific commit to the current branch.

  8. git bisect: Uses binary search to find a specific commit that introduced a bug.

  9. git tag: Adds a label to a specific commit in the repository, allowing you to mark a particular version.

  10. git fetch: Downloads any changes from the remote repository, but does not merge them into your local repository.

  11. git config: Allows you to configure Git, such as setting your username and email address.

  12. git blame <file>: Shows the commit and author responsible for each line of a file.

  13. git show <commit>: Shows the details of a specific commit, including the changes made and the commit message.

These commands can help you to perform more advanced version control tasks with Git, such as managing conflicts, manipulating the commit history, and debugging your code. Keep in mind that some of these commands can have complex behaviors and should be used with caution. It's always a good idea to understand the implications of a command before using it in your workflow.

Connect with me: Linkedin

Top comments (0)