DEV Community

Cover image for A-Z: Git Cheat Sheet🔥
Burak Boduroğlu
Burak Boduroğlu

Posted on • Updated on

A-Z: Git Cheat Sheet🔥

New Post 🆕

Boost Your Programming Efficiency: Essential Tools for Success ⚙️


What is the Git?

  • Git is a distributed version control system widely used in software development.
  • It was created by Linus Torvalds, the creator of the Linux operating system, in 2005.
  • Git allows multiple developers to collaborate on a project by keeping track of changes made to files and coordinating the merging of those changes.

Version Control:

  • Git is primarily used for version control, which means it keeps track of changes made to files over time. It allows you to view the history of changes, revert to previous versions, and manage different branches of development.

Repository:

  • A repository, often referred to as a "repo," is a central location where Git stores all the files and their complete history. It contains all the versions of the project and metadata about the changes.

Commit:

  • A commit is a snapshot of the project at a specific point in time. It represents a set of changes made to the files. Each commit has a unique identifier, and it includes information such as the author, timestamp, and a commit message.

Branch:

  • A branch is a separate line of development within a repository. It allows multiple developers to work on different features or bug fixes simultaneously without interfering with each other's code.

Merge:

  • Merging is the process of integrating changes from one branch into another. It combines the commits and resolves any conflicts that arise when changes overlap. This is often used to bring the changes made in a feature branch back into the master branch (usually called "master" or "main").

Remote:

  • A remote is a copy of a Git repository that is hosted on a server, allowing collaboration between developers. Popular remote repository hosting services include GitHub, GitLab, and Bitbucket.

Pull and Push:

  • Pulling refers to retrieving the latest changes from a remote repository and merging them into the local repository. Pushing means sending your local changes to the remote repository, making them available to other collaborators.

Useful Git Commands:

git init
Enter fullscreen mode Exit fullscreen mode
  • Initializes a new Git repository in the current directory. It creates a new .git subdirectory that stores the version control information.
git clone <repository>
Enter fullscreen mode Exit fullscreen mode
  • Creates a copy of a remote repository on your local machine. It downloads all the files and their entire history.
git add <file>
Enter fullscreen mode Exit fullscreen mode
  • Adds a file or changes to the staging area. This prepares the file to be committed.
git commit -m "<message>"
Enter fullscreen mode Exit fullscreen mode
  • Records a snapshot of the staging area as a new commit in the repository. The commit message describes the changes made in the commit.
git status
Enter fullscreen mode Exit fullscreen mode
  • Shows the current status of the repository. It displays which files are modified, staged, or untracked.
git diff
Enter fullscreen mode Exit fullscreen mode
  • Displays the differences between the current changes and the last commit. It shows the line-by-line differences in modified files.
git branch
Enter fullscreen mode Exit fullscreen mode
  • Lists all the branches in the repository. The current branch is marked with an asterisk.
git checkout <branch>
Enter fullscreen mode Exit fullscreen mode
  • Switches to a different branch. It updates the working directory to match the specified branch.
git merge <branch>
Enter fullscreen mode Exit fullscreen mode
  • Merges the specified branch into the current branch. It integrates the changes and creates a new commit.
git pull
Enter fullscreen mode Exit fullscreen mode
  • Fetches the latest changes from a remote repository and merges them into the current branch. It is often used to update the local repository with changes made by others.
git push
Enter fullscreen mode Exit fullscreen mode
  • Pushes local commits to a remote repository. It updates the remote repository with your changes, making them available to others.
git log
Enter fullscreen mode Exit fullscreen mode
  • Shows a history of commits in the repository. It displays commit messages, authors, timestamps, and commit identifiers.
git remote add <name> <url>
Enter fullscreen mode Exit fullscreen mode
  • Associates a remote repository with a name and URL. It allows you to refer to the remote repository by the given name.
git remote -v
Enter fullscreen mode Exit fullscreen mode
  • Lists all the remote repositories associated with the current repository along with their URLs.
git stash
Enter fullscreen mode Exit fullscreen mode
  • Temporarily saves changes that are not ready to be committed. It allows you to switch branches without committing or discarding the changes.
git stash pop
Enter fullscreen mode Exit fullscreen mode
  • Retrieves the most recently stashed changes and applies them to the current branch. It removes the changes from the stash once they have been applied.
git revert <commit>
Enter fullscreen mode Exit fullscreen mode
  • It undoes a previous commit by creating a new commit that contains the opposite changes. It allows you to safely undo changes without rewriting history.

  • Follow me on 👾 YouTube and Github link in bio.
  • Thank you for taking the time to read our blog post. Your support is greatly appreciated!🙋

References:

My other contents

Top comments (0)