Git commands: Boost your productivity with git
Tags: webdev, github, softwaredevelopment, developer
Published: 2024-01-11 07:58:34

Welcome everyone!

When I first started using Git, I have to admit, I was a bit intimidated. I had heard so much about it and knew it was an essential tool for any developer, but I didn't know where to begin. I struggled with understanding the basic commands and couldn't seem to wrap my head around the whole concept of version control.

I started by going through online tutorials, reading documentation, and experimenting with different commands. I would spend hours trying to understand the different branches, commits, and merge conflicts, but I was determined to make it work. And eventually, with a lot of practice and patience, it clicked.

I hope that by sharing my experience, I can help others who may be struggling with Git at the beginning. I know it can be overwhelming, but trust me, it's worth it. With the right mindset, patience and resources, you too can master Git and improve your workflow.

This guide is designed for both beginners and advanced users who want to master the art of Git and improve their workflow. Whether you are a new developer just starting out with version control or an experienced professional looking to optimize your Git skills, this guide has something for everyone. We will cover essential Git commands, advanced techniques, and helpful hacks that will help you work more efficiently and effectively with Git. So let's dive in and discover the full power of Git!

**

## What is git?
**
Git is a powerful version control system that allows developers to keep track of the changes made to their code. It allows developers to collaborate on projects, revert to previous versions of the code, and branch out to experiment with new features without affecting the main codebase.

One of the most important aspects of Git is being able to check the status of your files, including which files have been modified, added, or deleted. Developers can use git status command for that. Another important aspect of Git is being able to view the commit history, including when and who made the changes, and what changes were made. Developers can use git log command for that.

Git is widely used in software development and has become an industry standard for managing source code. It's also widely used in data science and machine learning projects.

For example, a software development team is working on a project. Each member of the team can clone the repository, make changes to their local copies, and push those changes back to the central repository. This allows the team to work on the project simultaneously without conflicts. Git also allows team members to easily revert to previous versions of the code or branch off to experiment with new features without affecting the main codebase.

In data science, git is useful for versioning the data, code and experiment. For example, as a data scientist, you could use git to version control your Jupyter notebooks and Python scripts, as well as the data you're using for your analysis. This allows you to easily reproduce your results and collaborate with other data scientists on the same project. Additionally, you can use git to version control your machine learning models and experiment with different versions of your model.

In summary, git is a powerful version control system that is widely used in software development and data science to manage source code and other files. It allows developers and data scientists to collaborate on projects, revert to previous versions of the code, and branch out to experiment with new features without affecting the main codebase.

## **Cheatsheet**

- view file status

```
git status
```

- view short status

```
git status --short
```

- view in machine readable format

```
git status --porcelain
```

> The --porcelain option causes git status to display the status in a machine-readable format, which is intended to be easy to parse by scripts and other automated tools.

**

## Viewing the Commit History
**

**view git logs**

```
git log
```
**view logs in single line**

```
git log --oneline
```
**view n numbers of logs**

```
git log -n
```
**single line & n number of logs**

```
git log --oneline -n
```
**log with patch changes**

```
git log --patch
```
**showing stats**

```
git log --stat
```

> stats: how many files were changed, and how many lines in those files were added and removed. It also puts a summary of the information at the end.

**sort stats**

```
git log --shortstat
```
**graphical view**

```
git log --graph
```
**logs without merge commits**

```
git log --no-merges
```
**showing references with dates**

```
git log --pretty=reference
```
**View git history of specific line**

```
git log --pretty=short -u -L <start line>,<end line>:<file path>
```
**Search for code within Git history**

```
git log -S "CodeSnippet or searchString"
```
**Search for commit message within Git history**

```
git log --grep=<pattern>
```

> TO BE CONTINUED