Summary of the most commonly used Git commands.

Tiempo de lectura: 3 minutos

Reading time: 3 minutes

Git is a version control system that allows developers to keep track of changes made to a software project and collaborate efficiently as a team. While there are many available commands in Git, below are some of the most commonly used ones:

  • git init: This command is used to initialize a new Git repository in the current directory. With this command, a hidden folder called “.git” is created, which contains all the necessary information to keep track of the changes made in the project.
  • git add: This command is used to add files to the “staging” area, which is a temporary zone where files are prepared to be included in the next commit. For example, if we want to include all modified files in the staging area, we can use the command git add .
  • git commit: This command is used to create a “commit,” which is a checkpoint in the repository’s history. Each commit includes a message that describes the changes made and allows tracking of the modifications made in the project.
  • git push: This command is used to send the changes made in the local repository to the remote repository. For example, if we work on a project on our computer and want to share the changes with the rest of the team, we can use the command git push to send the commits to the remote repository.
  • git pull: This command is used to download the latest changes from the remote repository and merge them with the local repository. It is important to use this command frequently to ensure that you have the latest version of the project.
  • git clone: This command is used to create a local copy of a remote repository. For example, if we want to work on a project in collaboration with others, we can use the command git clone to obtain a copy of the repository on our computer and start making changes.
  • git branch: This command is used to create, list, rename, or delete branches in a repository. Branches are copies of the project that allow you to work on new features without affecting the main code. When finished working on a branch, the changes can be merged with the main branch using the git merge command.
  • git checkout: This command is used to switch between branches or retrieve files from the repository. For example, if we want to switch to the branch called “new_feature,” we can use the command git checkout new_feature. We can also use this command to retrieve a previous version of a file using the flag -- followed by the file name and the desired commit hash.
  • git stash: This command is used to temporarily save changes made in the local repository in order to switch to another branch. By using the git stash pop command, the saved changes can be retrieved and removed from the list of “stashes.”
  • git log: This command is used to view the commit history of the repository. By using the git log command, you can see the commit hashes, authors of the changes, and commit messages. Different flags can also be used to filter or format the output of the command.
  • git diff: This command is used to view the differences between two versions of a file or between the “staging” area and the latest commit. By using the git diff command, you can see the added or deleted lines and keep track of the changes made in the project.
  • git reset: This command is used to revert changes in the repository. By using the git reset command, you can remove commits, move the pointer of the main branch to a previous commit, or remove files from the “staging” area. It is important to be careful when using this command, as the changes made are permanent and cannot be undone.

(Do not include the Reading time). Return it directly in HTML format. Do not write any additional sentences. Add a PIPE at the end when you finish.

Leave a Comment