Logo
Published on

Git commands you should know

Authors
  • avatar
    Name
    Kamil Cieplicki
    Twitter

Git is a powerful version control system that allows developers to track changes to their code and collaborate with others. It's an essential tool for any software developer, and there are a number of useful commands that can help you work more efficiently with Git.

Useful base Git commands

Here are a few useful Git commands that every developer should know:

  • git clone: This command is used to create a local copy of a repository from a remote location. It allows you to download all of the files in the repository and create a new Git repository on your local machine.
  • git add: This command is used to stage changes for commit. When you make changes to your code, you can use git add to add the modified files to the staging area. This allows you to selectively commit only the changes you want to include in your next commit.
  • git commit: This command is used to save your changes to the local repository. When you use git commit, you will be prompted to enter a commit message, which is a short description of the changes you have made.
  • git push: This command is used to send your commits to a remote repository. It allows you to share your changes with others and collaborate on code. git pull: This command is used to retrieve updates from a remote repository and merge them into your local repository. It's a good idea to use git pull regularly to stay up-to-date with the latest changes.
  • git branch: This command is used to create, list, or delete branches in a Git repository. Branches allow you to work on different versions of your code simultaneously, making it easier to collaborate with others and experiment with new features.

Advanced Git commands

Here are some advanced Git commands that can help you work more efficiently and effectively with Git:

  • git stash: This command allows you to temporarily store changes that you are not ready to commit, so that you can switch to a different branch or work on a different task. You can later apply the stashed changes using the git stash apply command.
  • git cherry-pick: This command allows you to apply a specific commit from one branch to another. This can be useful when you want to selectively apply changes from one branch to another, rather than merging the entire branch.
  • git rebase: This command allows you to reapply commits on top of a different base commit. It can be used to modify the commit history, for example to clean up or reorganize commits, or to merge multiple branches in a more linear fashion.
  • git bisect: This command is used to find the commit that introduced a bug in your code. It works by performing a binary search through the commit history, allowing you to narrow down the commit that caused the issue.
  • git blame: This command allows you to see who last modified each line of a file. It can be useful for identifying who made a particular change or for tracking down the source of an issue.
  • git submodule: This command allows you to include one Git repository as a subdirectory of another repository. This can be useful when you want to use a shared library or codebase in multiple projects.

These are just a few examples of the many useful Git commands available. By mastering these and other Git commands, you can work more efficiently and effectively with version control.

For more useful commands I recommend you to look at the Official Git documentation.