← Back to Tutorials

Getting Started with Git and GitHub

DevOps

What are Git and GitHub?

Git is a distributed version control system used to manage and track changes in source code during software development.

GitHub is a platform that hosts Git repositories online, making it easier for teams to collaborate, review code, and manage version control.

How to Install Git

Linux

sudo apt update
sudo apt install git

Windows

Download Git from git-scm.com and run the installer.

macOS

brew install git

Configuring Git

Step 1: Set Username

git config --global user.name "Your Name"

Step 2: Set Email

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

Basic Git Commands

Initialize a Repository

git init

Check the Status of Your Repository

git status

Add Files to Staging

git add filename
git add .

Commit Changes

git commit -m "Your commit message"

View Commit History

git log

Connecting Git with GitHub

Step 1: Create a New Repository on GitHub

Go to GitHub, create a new repository, and name it as desired. Copy the repository URL.

Step 2: Link Your Local Repository to GitHub

git remote add origin https://github.com/username/repository-name.git

Step 3: Push Changes to GitHub

git push -u origin master

Basic Workflow with Git and GitHub

  • Make changes: Modify your files locally.
  • Stage changes: Add files with git add.
  • Commit: Save changes with a descriptive message using git commit.
  • Push: Upload changes to GitHub using git push.
  • Pull: Sync your local repository with updates from GitHub using git pull.