Skip to main content

Command Palette

Search for a command to run...

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

Updated
4 min read
A Complete Guide to Git & GitHub: Hands-On Learning
P

I am a cloud enthusiast with expertise in designing scalable and secure cloud solutions. I have hands-on experience in Docker for efficient containerization and application deployment. Passionate about simplifying complex technologies, I share my knowledge through informative blogs to inspire and educate others in the tech community.

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

FeatureGitGithub
TypeVersion control systemCloud-based hosting service
FunctionalityTrack Changes locallyEnables collaboration & remote repo
InstallationInstalled Locally on your MachineNo installation required, web based
Use CaseManaging Project HistorySharing 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 and follow the installation steps.

  2. Configuring Git:

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

This sets your identity for commit history.

Initializing a Repository

To start tracking a project with Git:

git init

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

Key Git Commands that i Used

  1. git status – Checks the current state of files in the working directory.

  2. git add . – Stages all changes to be committed.

  3. git commit -m "message" – Saves staged changes with a descriptive message.

  4. git log – Displays commit history in the repository.

  5. git push – Sends local commits to a remote repository.

  6. git checkout - is used to switch between branches or restore files in your working directory to a specific state.

  7. git merge – Integrates changes from one branch into another.

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:

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.

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

ssh -T git@github.com

.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:

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.