Git Commands To Know As A Developer [Cheatsheet for Beginners] 👨‍💻📑
Tags: github, git, cheatsheet, productivity
Published: 2023-08-25 12:07:52

Done with remembering Git commands? Check out this cheat sheet with 10 commands to make your life easier as a code newbie.

You before this post -
![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bs57hlwwfq9n2nxswxyx.png)You after this post -
![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/452u336qrxplhan0h1n6.png)

### Some Simple Git Terms To Know:

- **Repository**: This is where all your project's files, changes, and different versions are stored.

- **Branch**: It's like a separate copy of your project where you can work on a specific version. The main branch is often called "master."

- **Commit**: Think of it as a single snapshot of the changes you've made to your project in a branch.

- **Checkout**: This is how you switch between the current version you're working on and another version in your project.

- **Master**: The main version of your project, usually referred to as the "master" branch.

- **Merge**: When you combine changes from one branch into another to keep everything up to date.

- **Fork**: A clone of a repository that you can work on independently.

- **Head**: The most recent snapshot of your project that you're currently working with.

### Fundamental Git Commands You Need to Grasp

```js
git init | git init [folder]
```
To start a new project or set up version control in an existing project, you use this command. It creates a repository either in the current folder or the specified folder.

```js
git clone [repo URL] [folder]
```
This command copies an existing repository to your computer. If you provide a repo URL, it copies to the current location. If you want it in a different location, include a folder path.

```js
git add [directory | file]
```
When you want to prepare changes to be saved, this command comes in handy. It stages the changes in a directory or a file. Usually followed by git commit and git push.

```js
git commit -m "[message]"
```
After staging changes, this command commits them with a message explaining the changes. You can also use -am to add and commit changes together.

```js
git push
```
To send your committed changes to the main repository, you use this command.

```js
git diff
```
To see the differences between your current changes and the last committed version, you use this command. You can also compare staged changes with the latest version using -staged, or specify a file to compare.

```js
git pull
```
This command is used to fetch changes from the original branch and merge them into your local branch.

```js
git fetch
```
Similar to git pull, this command gets the latest changes from the main branch, but it doesn't automatically merge them.

```js
git log
```
This shows the history of your commits in a default format, letting you see what changes have been made over time.

```js
git status
```
This helps you know the status of your files, whether they're ready to be committed, changed, or untracked.

Use [this](https://education.github.com/git-cheat-sheet-education.pdf) official cheatsheet of Git for more commands.

I hope this article has helped you in learning about Git. Thanks for reading the article! Don't forget to bookmark this post for reference in the future!