A-Z: Git Cheat Sheet🔥
Tags: webdev, programming, tutorial, git
Published: 2023-06-10 10:42:42

### New Post 🆕 
> [Boost Your Programming Efficiency: Essential Tools for Success ⚙️](https://dev.to/burakboduroglu/boost-your-programming-efficiency-essential-tools-for-success-5h00)

---

### 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
```
- Initializes a new Git repository in the current directory. It creates a new .git subdirectory that stores the version control information.

```
git clone <repository>
```
- Creates a copy of a remote repository on your local machine. It downloads all the files and their entire history.

```
git add <file>
```
- Adds a file or changes to the staging area. This prepares the file to be committed.

```
git commit -m "<message>"
```
- 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
```
- Shows the current status of the repository. It displays which files are modified, staged, or untracked.

```
git diff
```
- Displays the differences between the current changes and the last commit. It shows the line-by-line differences in modified files.

```
git branch
```
- Lists all the branches in the repository. The current branch is marked with an asterisk.

```
git checkout <branch>
```
- Switches to a different branch. It updates the working directory to match the specified branch.

```
git merge <branch>
```

- Merges the specified branch into the current branch. It integrates the changes and creates a new commit.

```
git pull
```
- 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
```
- Pushes local commits to a remote repository. It updates the remote repository with your changes, making them available to others.

```
git log
```
- Shows a history of commits in the repository. It displays commit messages, authors, timestamps, and commit identifiers.

```
git remote add <name> <url>
```
- 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
```
- Lists all the remote repositories associated with the current repository along with their URLs.

```
git stash
```
- 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
```
- 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>
```
- 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!🙋

---

#### <u>References:</u>
- [ChatGPT](https://openai.com/blog/chatgpt)

## My other contents
- [Building a Node.js Server Without Using Express.js🐤](https://dev.to/burakboduroglu/building-a-nodejs-server-without-using-expressjs-3mc8)


- [A-Z: MongoDB Cheat Sheet🌱](https://dev.to/burakboduroglu/mongodb-cheat-sheet-1a6a)

- [Boost Your Programming Efficiency: Essential Tools for Success ⚙️](https://dev.to/burakboduroglu/boost-your-programming-efficiency-essential-tools-for-success-5h00)

- [JS Guide: Map, Reduce, Filter and forEach Methods](https://dev.to/burakboduroglu/js-guide-map-reduce-filter-and-foreach-methods-5fmi)

- [Understanding CORS and Same Origin Policy in Web Security🚨](https://dev.to/burakboduroglu/understanding-cors-and-same-origin-policy-in-web-security-54hm)