# A Complete Guide to Git & GitHub: Hands-On Learning

Version control is one of the most essential skills for developers, and Git along with GitHub is the industry standard for managing code efficiently. In this blog, I will share what I learned about Git and GitHub, the differences between them, repositories, key commands, authentication methods, and how they are crucial in DevOps.

## What is Git?

Git is a distributed version control system that helps developers track changes in their code. It allows multiple people to work on a project simultaneously without overwriting each other’s work. Git stores snapshots of your project at different points in time, making it easy to roll back changes or review history.

## What is GitHub?

GitHub is a cloud-based platform that hosts Git repositories. It enables collaboration by allowing developers to share their code, submit pull requests, review changes, and contribute to open-source projects. While Git manages the code locally, GitHub provides a remote backup and collaboration tools.

## Difference Between Git and GitHub

| **Feature** | **Git** | **Github** |
| --- | --- | --- |
| Type | Version control system | Cloud-based hosting service |
| Functionality | Track Changes locally | Enables collaboration & remote repo |
| Installation | Installed Locally on your Machine | No installation required, web based |
| Use Case | Managing Project History | Sharing code, Collaboration, CI/CD |

## **Repositories**

A **repository (repo)** is a place where your project files and their history are stored. Git supports different types of repositories:

* **Local Repository**: Exists on your local machine.
    
* **Remote Repository**: Hosted on platforms like GitHub, GitLab, or Bitbucket.
    

## **Hands-On Learning: Installing Git & Configuration**

1. **Installing Git**:  
    Download Git from [git-scm.com](https://git-scm.com/?utm_source=chatgpt.com) and follow the installation steps.
    
2. **Configuring Git**:
    

```plaintext
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756452260200/e9b92a23-a9f7-40e4-aa10-2afc2c5a96f0.png align="center")

This sets your identity for commit history.

## **Initializing a Repository**

To start tracking a project with Git:

```plaintext
git init
```

This creates a `.git` folder in your project directory, enabling version control.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756452586954/b594f479-a17a-447e-9bee-7f4431a24bdd.png align="center")

## **Key Git Commands that i Used**

1. `git status` – Checks the current state of files in the working directory.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453017897/00e0148e-e24e-443b-a6f1-984ab7d1a0fc.png align="center")
    
2. `git add .` – Stages all changes to be committed.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453073714/e919f134-008d-49ab-bd08-e34d3a810e33.png align="center")
    
3. `git commit -m "message"` – Saves staged changes with a descriptive message.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453122301/6013b0a1-27ed-4398-bcda-5cbab246bcff.png align="center")
    
4. `git log` – Displays commit history in the repository.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453192859/25c77f6d-8786-4f91-88f4-671270eda148.png align="center")
    
5. `git push` – Sends local commits to a remote repository.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453690308/36638e4d-77d4-406e-abcb-7305306e4799.png align="center")
    
6. `git checkout` - is used to **switch between branches** or **restore files** in your working directory to a specific state.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453337537/344749b6-6a24-4ec9-86ca-5617d09af915.png align="center")
    
7. `git merge` – Integrates changes from one branch into another.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756453619060/95055c09-39ce-4fb4-915a-3b811c6f396e.png align="left")
    

## **Authentication in GitHub**

To interact with GitHub securely, authentication is required:

* **HTTPS**: Uses your GitHub username and personal access token for authentication.
    
* **SSH**: Uses SSH keys to authenticate without entering credentials repeatedly:
    

```plaintext
ssh-keygen -t rsa -b 4096 -C “pujanbhattarai361@gmail.com”
ls -la ../.ssh/
cat ~/.ssh/id_rsa.pub
```

SSH is recommended for convenience and security.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756454634790/8ae90671-2dc9-4d53-b4d7-fa9120419ec3.png align="center")

Now, Add the SSH key in github, go to Github Settings → SSH and GPG Keys → New SSH keys.

```plaintext
ssh -T git@github.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1756454729882/cbe214c2-5cd2-4926-8feb-a5fffba94c5f.png align="center")

## **.gitignore**

The `.gitignore` file tells Git which files or directories to ignore. For example, sensitive data, log files, or IDE settings should not be tracked:

```plaintext
node_modules/
*.log
.env
```

## **Git with VS Code**

Visual Studio Code integrates Git natively:

* View changes in the **Source Control** panel.
    
* Stage, commit, pull, and push directly from the editor.
    
* Provides visual diff tools to compare changes.
    

Using Git with VS Code makes version control more intuitive, especially for beginners.

## **Importance of Git & GitHub in DevOps**

Git and GitHub are fundamental in **DevOps** for several reasons:

* **Collaboration**: Teams can work on multiple branches simultaneously.
    
* **Continuous Integration/Deployment (CI/CD)**: GitHub repositories integrate with pipelines to automate testing and deployment.
    
* **Traceability**: Every change is tracked with commits, making debugging easier.
    
* **Backup**: Remote repositories serve as a cloud backup for code.
    

Mastering Git and GitHub is a crucial step toward a career in DevOps or cloud-native development.

## **Conclusion**

Learning Git and GitHub hands-on has been a game-changer for me. From initializing repositories, committing changes, pushing and pulling updates, to creating branches and collaborating via pull requests, I now understand how version control and cloud collaboration work together to streamline software development.

Git and GitHub are more than just tools—they are **essential skills** for every modern developer and DevOps engineer.
