A Git cheat sheet – $get git
Tags: beginners, webdev, devops, cloud
Published: 2022-04-29 04:09:11

## DAY 29 - A Git cheat sheet – $get git - Day Twenty Nine

[![Image tweet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfjzxg64r7q0i8ra6b8t.png)![git](https://ictpro.co.nz/wp-content/uploads/2021/02/Add-a-heading-1024x576.png)](https://twitter.com/intent/tweet?text=A%20Git%20cheat%20sheet%20%E2%80%93%20%24get%20git%20%2Ca%20blog%20by%20%40anuvindhs%0A%0Ahttps%3A%2F%2Fdev.to%2Fanuvindhs%2Fa-git-cheat-sheet-get-git-2jm3)
[100 days of Cloud on GitHub](https://github.com/anuvindhs/100daysofcloud) - [Read On iCTPro.co.nz](https://ictpro.co.nz) - [Read on Dev.to](https://dev.to/anuvindhs)

------

**Git Commands Comes handy**

Git is a highly matured open-source software that is famous for tracking changes and collaboration among programmers. Git plays a major role in DevOPS for source code management.

The git is very efficient in speed, data integrity, and support for distributed, non-linear workflows



### Basic Git commands

- Clone a repository 

```git
git clone [url]
```


- Start a new repository

```
git init [repository]
```


- Add file to the staging area

```
git add [filename]
```


- Save changes to repository & commit

```
git add .
git commit -m " my first commit"
```


- Status of repository

```
git status 
```


- Show difference which you are not staged

```
git log
```


- Differences between the two branches – branch_1 and branch_2

```
git diff branch_1 branch_2
```
 


- Get the entire commit history 

```
git diff branch_1 branch_2 
```

### Git Undo

- Undo the previous commit

```
git revert HEAD^ 
```


- Revoke from the staging area but leave the working directory unchanged

```
git reset [file] 
```

- Shows which files be removed from the working directory
```
git clean -n 
```

### Git Branches

- List all branchs

```
git branch
```

- Create new branch
```
git branch [NameOfBranch]
```

- List all branches
```
git branch -a
```

- Deleting a branch
```
git branch -d [NameOfBranch]
```

- Merging all changes to current branch
```
git merge [NameOfBranch]
```

- Checking an existing branch
```
git checkout [NameOfBranch]
```

### Git Tag

- Creating a tag
```
git tag [TagName]
```

- Deleting a tag
```
git tag -d [TagName] 
```

-  Push tags
```
git push --tags
```

### Git Remote repositories

- Getting latest version of the repository
```
git pull[NameOfBranch] [url]
```

- Gets a specific [branch] from the repo
```
git fetch [remote_url] [branch] 
```

- Get  speficif remote copy of branch
```
git pull [remote_url]
```

- Push branch to remote

```
git push [remote_url] [BrnaceName]
```

### Git Delete

- Deleting file – Force
```
git rm -f [NameOfFile]
```

- Remove the entire Directory from the working index
```
git rem -r --cached [NameofDirecotry]
```

- Deleting an entire directory
```
git rm -r -f [NameofFile]
```

----------

**✅Connect with me on [Twitter](https://twitter.com/intent/follow?ref_src=anuvindhs&screen_name=anuvindhs)
 🤝🏽Connect with me on [Linkedin](https://www.linkedin.com/in/anuvindhs)
🧑🏼‍🤝‍🧑🏻 Read more post on [dev.to](https://dev.to/anuvindhs) or  [iCTPro.co.nz](https://ictpro.co.nz)
💻 Connect with me on [GitHub](https://github.com/anuvindhs)**

----------
{% user anuvindhs %}