Quick Office Pointe Logo

A Beginner’s Guide to Git and GitHub

by Charles Kinaro Nov 04, 2024
A Beginner’s Guide to Git and GitHub

If you’re just getting started in software development, you may have heard of Git and GitHub. These are essential tools in modern coding and are widely used by developers to manage, track, and collaborate on code. In this beginner’s guide, we’ll cover what Git and GitHub are, why they’re essential, and walk through some basic commands to help you get started.

What is Git?

Git is a version control system that tracks changes in code, allowing multiple developers to collaborate on projects efficiently. It manages code history, supports branching for parallel development, and lets users revert to previous versions if needed.

What is GitHub?

GitHub is a platform for hosting and managing Git repositories online. It enables collaboration, version control, and sharing of code projects, with additional features like issue tracking, pull requests, and continuous integration tools.

How Git and GitHub Work Together

Git tracks your code changes locally, and GitHub helps you share and manage those changes online. You use Git to create and manage the local versions of your projects, while GitHub allows you to push (upload) your code to a remote repository so that others can access it.

Getting Started with Git: Basic Commands

Installing Git

First, you’ll need to install Git on your computer. You can download it from HERE, and it’s available for Windows, macOS, and Linux. Once installed, you’ll be able to use Git commands in your terminal or command prompt.

Configuring Git

Before you start using Git, configure it with your name and email address, which will be linked to your commits.

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

Creating Your First Repository

A repository (or repo) is where your project files and their history are stored. Here’s how to create a new Git repository:

Initializing a Repository

In your project folder, initialize a new repository by running on the terminal:

git init

This command sets up a new Git repository in your project folder, allowing Git to start tracking your changes.

Adding Files

Once you’ve made changes to files (like creating a new file or modifying an existing one), you need to add them to the staging area. This area prepares files for the next commit (or saved state).

git add filename

You can replace filename with a specific file’s name or use . to add all files at once:

git add .

Committing Changes

Once you’ve added files to the staging area, commit them with a descriptive message:

git commit -m "Add initial files"

Working with GitHub

Now that you know how to use Git locally, you can learn how to upload your work to GitHub.

Creating a Repository on GitHub

Log in to GitHub, click on “New repository,” and fill in the repository’s details. Once created, GitHub will provide you with a URL for the repository.

Connecting Your Local Repository to GitHub

To connect your local Git repository to GitHub, use the following command, replacing URL with the URL of your GitHub repository:

git remote add origin URL

Pushing Your Code to GitHub

Now, upload (push) your local changes to GitHub:

git push -u origin main

This command uploads your code to the main branch on GitHub. You only need to use -u origin main the first time; afterward, just use git push to upload new changes.

Other Useful Git Commands to Know

git status: Shows the status of your files in the working directory, including any changes not yet staged or committed.

git log: Displays the commit history for your project. This is useful to see previous changes and who made them.

git branch: Lists all branches in your repository. Branches are like parallel versions of your project, allowing you to work on new features without affecting the main code.

git checkout branch-name: Switches to the specified branch.

git merge branch-name: Merges the specified branch into your current branch, combining changes from both branches.

175 views