Git and GitHub Basics: A Beginner’s Tutorial

:rocket: Git and GitHub Basics: A Beginner’s Tutorial

Whether you’re a developer, data scientist, or student learning to code, understanding Git and GitHub is essential. They are the backbone of modern version control and collaboration in software projects. This guide will walk you through the basics of Git and how to use GitHub effectively.

:wrench: What is Git?

Git is a version control system that tracks changes in your files and allows multiple people to work on a project without overwriting each other’s work.

Key Features:

  • Track and manage code history
  • Revert to previous versions
  • Collaborate with others efficiently
  • Branching and merging for parallel development

:octopus: What is GitHub?

GitHub is a cloud-based platform that hosts your Git repositories. It allows teams to collaborate on code, review pull requests, and manage projects efficiently.

It provides:

  • Remote repositories
  • Collaboration tools (pull requests, issues, etc.)
  • GitHub Actions (for automation)
  • Community and open-source access

:hammer_and_wrench: Getting Started with Git and GitHub

1. Install Git

Download Git from the official site:
:backhand_index_pointing_right: https://git-scm.com/

Verify installation:

git --version

2. Set Up Git

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

This sets your identity for commits.


3. Create a Local Repository

mkdir my-project
cd my-project
git init

This initializes a new Git repository in the folder.


4. Add and Commit Files

touch index.html
git add index.html       # Stage the file
git commit -m "Initial commit"   # Commit with a message

5. Create a Repository on GitHub

  1. Go to https://github.com
  2. Click New Repository
  3. Name it (e.g., my-project)
  4. Click Create Repository

6. Link Local Repo to GitHub

git remote add origin https://github.com/yourusername/my-project.git
git branch -M main
git push -u origin main

7. Cloning a Repository

If someone else shares a repo with you:

git clone https://github.com/username/repo-name.git

8. Basic Git Workflow

git pull             # Get latest changes
git add .            # Stage all changes
git commit -m "Update"
git push             # Send changes to GitHub

:deciduous_tree: Branching and Merging

Branching lets you work on features independently.

git checkout -b feature-branch
# work on code
git add .
git commit -m "Add feature"
git checkout main
git merge feature-branch
git push

:white_check_mark: Common Git Commands

Command Description
git status Show changed files
git log View commit history
git diff View file changes
git stash Temporarily save changes
git reset Undo commits or staged files
git rm Remove files

:handshake: Collaborating on GitHub

  1. Fork a repository
  2. Clone your fork locally
  3. Create a new branch and make changes
  4. Push the branch and create a Pull Request
  5. Collaborators review and merge your PR

:brain: Tips for Beginners

  • Commit often with meaningful messages
  • Keep your branches small and focused
  • Always pull before you push
  • Use .gitignore to avoid committing unnecessary files

:end_arrow: Conclusion

Git and GitHub are essential tools in every developer’s toolkit. Once you understand the basic workflow, you’ll be able to manage projects, collaborate on code, and contribute to open-source software with confidence.