Breaking

Post Top Ad

Your Ad Spot

Monday, April 7, 2025

How to Use Git and GitHub for Beginners

How to Use Git and GitHub for Beginners

Git is a version control system that lets you track changes in your code and collaborate with others. GitHub is a platform for hosting Git repositories online, allowing multiple developers to work on projects simultaneously. This guide will help beginners get started with Git and GitHub.

What You’ll Need

To follow along, make sure you have:

  • A computer running Windows, macOS, or Linux
  • Internet connection
  • A GitHub account (Sign up here)

Step 1: Installing Git

Install Git based on your operating system:

For Windows:

  1. Go to git-scm.com
  2. Download the Windows installer and run it
  3. Use default settings and complete the installation

For macOS:

  1. Open Terminal and run:
    xcode-select --install
  2. This installs Git along with developer tools

For Linux:

  1. Open Terminal and run:
    sudo apt update
    sudo apt install git

Step 2: Configure Git

After installing Git, set up your name and email:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Step 3: Creating a GitHub Repository

  1. Log in to your GitHub account
  2. Click the + icon in the top-right and choose New repository
  3. Enter a repository name and click Create repository

Step 4: Cloning a Repository

To copy the repository to your computer:

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

Step 5: Making Changes

Navigate into your project folder and edit or create files. Then run:

git add .
git commit -m "Your commit message"
git push origin main

This stages, commits, and uploads your changes to GitHub.

Step 6: Pulling Changes

To get the latest updates from GitHub:

git pull origin main

Step 7: Viewing Git History

To see your commit history:

git log

Press q to quit the log view.

Basic Git Commands

  • git status – Check current changes
  • git diff – View file differences
  • git branch – List branches
  • git checkout -b new-branch – Create a new branch
  • git merge branch-name – Merge a branch into current branch

Using .gitignore

Create a file named .gitignore in your repository to exclude certain files or folders from being tracked by Git.

# Example .gitignore
node_modules/
*.log
.env

Syncing with GitHub

Use the following to keep your local and remote repos in sync:

git fetch
git merge
git push
git pull

No comments:

Post a Comment

Post Top Ad

Your Ad Spot