GIT - Beginner’s Guide: Useful GIT commands you should know
Tags: git, github, webdev, programming
Published: 2023-12-24 08:07:30

Technology: GIT
Series: Beginner's Guide
Topic: Useful GIT commands you should know
Version: 1.1
Author: Cezary Mazur
Author Website: [https://cezarymazur.pl](https://cezarymazur.pl/)

Version control is a crucial aspect of modern software development, and Git stands out as one of the most popular version control systems. If you're a beginner navigating the vast world of Git, this guide will provide you with essential commands to kickstart your journey. From basic operations to more advanced features, we'll explore the functionalities that will make your development workflow smoother.

---

## **Understanding Git Basics**

Each command in this article should be executed in a terminal in your project folder.

### Initializing a Repository

To start using Git, you need to initialize a repository. This is where Git will track changes in your project.

```bash
git init
```

### Cloning a Repository

If you're working on an existing project - for example project with the repository in GitLab, BitBucket, or GitHub - you can clone it to your local machine.

```bash
git clone <repository-url>
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2t2bwzzjsib0706b3cw.png)

---

## **Day-to-Day Commands**

### Tracking Changes

Once your repository is set up, you'll make changes to your code. The following commands help you track and commit those changes.

```bash
git add <filename>
git commit -m "Your commit message"
```

### Checking Status

It's crucial to know the status of your repository at any given time.

```bash
git status
```

### Viewing Commit History

Understanding the commit history is essential for collaboration and debugging.

```bash
git log
```

### **Collaborating with Others**

### Pulling Changes

If someone else has made changes to the repository, you need to pull those changes to your local machine.

```bash
git pull
```

### Pushing Changes

When you've made changes and want to share them with others, you push your commits.

```bash
git push
```

### Branching

Branching allows you to work on new features or bug fixes without affecting the main codebase.

```bash
git branch <branch-name>
git checkout <branch-name>
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ygk7437q1y6saebo1eg.png)

---

## **Advanced Git Commands**

### Merging Branches

Once you've completed your work on a branch, you merge it back into the main branch.

```bash
bashCopy code
git merge <branch-name>

```

### Resolving Conflicts

Conflicts may arise when merging branches with conflicting changes. Resolve them using:

```bash
git mergetool
```

## **Pros and Cons of Git**

### ✅ Pros

1. **Distributed Version Control:** Git allows decentralized collaboration, enabling developers to work offline and merge changes seamlessly.
2. **Branching and Merging:** The ability to create branches and merge them easily facilitates collaborative development and feature isolation.
3. **Fast and Efficient:** Git is designed to be quick, making it ideal for both small and large projects.

### **😥** Cons

1. **Learning Curve:** For beginners, Git's extensive feature set can be overwhelming, leading to a steep learning curve.
2. **Confusing Terminology:** Concepts like "rebase" and "detached HEAD" can be confusing for new users.
3. **Storage Size:** Repositories with a long history can consume significant disk space.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ca0zjc6a6jn20dx8s388.png)

---

## **Tips for Efficient Git Usage**

1. **Regularly Commit:** Make small, frequent commits to create a comprehensive commit history.
2. **Use Branches Wisely:** Create branches for new features or bug fixes to keep the main branch stable.
3. **Write Meaningful Commit Messages:** Clearly articulate the purpose of each commit for better collaboration.

### **Visualizing Git Concepts**

Images can help visualize Git workflows. Consider using icons or diagrams to illustrate concepts like branching, merging, and commit history.

---

## How to learn Git?

### Courses

One of the best ways to learn Git is through courses. You can find many of them for free on YouTube or purchase a course on Udemy. Regardless of which course you choose, it will help you better understand and implement the use of GIT.

### Games

I highly recommend games that can help you learn Git and its commands:

1. LearnGitBranching: https://learngitbranching.js.org/
2. OhMyGit: https://ohmygit.org/

---

## **Leaving Comments, Reacting, and Saving the Article**

I hope this guide provides you with a solid foundation for using Git. If you have any questions or thoughts, please leave a comment below. 

Your feedback is valuable to me! If you found this article helpful, consider reacting to it and saving it for future reference.

### **Explore More**

For further insights and in-depth tutorials, visit [author's website](https://cezarymazur.pl/). 

Stay tuned for more articles on front-end development, and 😀 happy coding!