Skip to main content

Command Palette

Search for a command to run...

Mastering GitHub: A Comprehensive Guide

Published
•3 min read•View as Markdown
H

👋 Hey there! I'm Hitesh Mungara 🚀 Aspiring Software Engineer | AI & Cloud Enthusiast

I’m a Computer Science student at Amrita Vishwa Vidyapeetham (Graduating 2025), passionate about AI, NLP, Cloud Computing, and Full-Stack Development.

🔹 Tech Stack: Java, Python, PostgreSQL, MySQL, React Native, Docker, Kubernetes 🔹 ML/AI Interests: Deep Learning, NLP, Computer Vision, Predictive Analytics 🔹 Projects: Virtual Classroom, Stock Market Prediction, Text Summarization, Attendance Management System 🔹 Open Source & DevOps: Exploring Git, GitHub, CI/CD, and containerization

I enjoy solving real-world problems through code, research, and innovation while contributing to the developer community. Always eager to learn, build, and share my journey.

📢 Follow my blog for insights on AI, software development, and tech trends.

Let’s connect and build something amazing! 🚀

GitHub is an essential tool for developers, enabling version control, collaboration, and open-source contributions. Whether you're a beginner or an experienced developer, mastering GitHub commands and workflows is crucial for efficient development. In this guide, we'll explore important Git and GitHub commands, branching, stashing, rebasing, and open-source contributions.

Understanding Git Configuration

Git stores your credentials and settings in a configuration file. You can check it using:

cat .gitconfig

This file resides in the starting directory and holds user information and other Git settings.

Essential Git Commands

Initializing a Repository

To start tracking a project with Git:

git init

Staging and Committing Changes

git add .  # Stages all changes
git commit -m "Your commit message"  # Commits changes

To add and commit changes in one step:

git commit -am "Your commit message"

Branching

Branches allow parallel development. Key branch-related commands:

git branch  # List branches
git branch -M main  # Rename branch to main
git checkout -b new-branch  # Create and switch to a new branch
git branch -d branch-name  # Delete a branch

Switching Between Commits

git checkout branch-name  # Switch to a branch
git checkout master  # Go to the latest commit
git checkout HEAD~2  # Move back two commits
git restore filename  # Undo the last change

Understanding Changes with Git Diff

To compare changes before committing:

git diff --staged  # Show differences between staged and committed files
git diff branch1 branch2  # Compare two branches

Stashing Changes

When you need to switch branches without committing changes, use stash:

git stash  # Save changes temporarily
git stash list  # View stashed changes
git stash apply stash@{n}  # Apply a specific stash
git stash pop  # Apply and remove a stash
git stash drop stash@{n}  # Remove a stash

Rebasing: A Word of Caution

Rebasing is useful but should not be done on the master branch. To rebase:

git rebase branch-name  # Apply changes from another branch

Working with Remote Repositories

Connecting to a Remote Repository

git remote -v  # View remote connections
git remote add origin <repo-url>  # Add a remote repository

Pushing Changes

git push -u origin main  # Push changes to the remote repo

After setting upstream, simply use:

git push

Open-Source Contributions on GitHub

Forking and Cloning a Repository

To contribute to an open-source project:

  1. Fork the repository on GitHub.

  2. Clone it to your local machine:

     git clone <repo-url>
    
  3. Create a new branch:

     git branch feature-branch
     git checkout feature-branch
    
  4. Make changes, commit, and push:

     git commit -am "Added new feature"
     git push origin feature-branch
    
  5. Open a Pull Request (PR) on GitHub.

Learning Git Branching

For an interactive learning experience, check out: Learn Git Branching


This guide covers fundamental GitHub commands and best practices for efficient version control and collaboration. Keep experimenting and contributing to open-source projects to refine your skills!