MyAssignmentHelp.usGet Support
Resources/Programming

Git & GitHub Basics: A Beginner's Guide

Git helps you track changes to code, while GitHub provides a place to store and collaborate on Git repositories online. This guide explains the core concepts and commands you need to understand a basic Git and GitHub workflow.

The main idea

Git and GitHub are related, but they are not the same thing. Git tracks versions of your project. GitHub can host a Git repository remotely and provide tools for collaboration, review, and project management.

01

What Is the Difference Between Git and GitHub?

This distinction is one of the first things to understand when learning version control.

Git

Git is a distributed version control system. It records changes to files and allows you to work with different versions of a project.

GitHub

GitHub is a platform that can host Git repositories online and provide collaboration features around them.

You can use Git without GitHub. You can create commits, branches, and version history entirely on your own computer.

GitHub becomes useful when you want a remote copy of the repository or need features such as pull requests, issue tracking, code review, and collaboration.

A useful way to remember the distinction is: Git manages the version history; GitHub can host and help people collaborate around that Git repository.

02

What Is a Repository?

A repository, often shortened to repo, is the project being tracked by Git along with its version history and related Git information.

If you already have a project folder and want Git to start tracking it, you can initialize a repository.

TERMINAL

Initialize Git

git init

This initializes a Git repository in the current directory.

Before running the command, make sure your terminal is in the correct project folder. Accidentally initializing Git in the wrong directory can create confusion about which files belong to the repository.

03

Understand the Basic Git Workflow

At a beginner level, it helps to think about your files moving through a few stages.

1

You create or edit files in your working directory.

2

You choose which changes should be staged.

3

You commit the staged changes to the repository history.

4

When using a remote repository, you can push your commits to it.

This means saving a file in your code editor is not the same as creating a Git commit, and creating a local commit is not the same as uploading that commit to GitHub.

04

Check What Has Changed With git status

One of the most useful Git commands for beginners is:

TERMINAL

Check Repository Status

git status

This command helps you see information such as which files have changed, which files are untracked, and which changes are staged for the next commit.

When you are unsure about the current state of your repository, git status is often a useful place to start.

05

Stage the Changes You Want to Commit

Git allows you to choose which changes should be included in the next commit.

To stage a particular file:

TERMINAL

Stage One File

git add page.tsx

To stage changes under the current directory:

TERMINAL

Stage Changes

git add .
Review what you are staging

git add . can stage multiple changed and untracked files. Check the repository status so you do not accidentally include files that should remain outside the commit.

06

Create a Commit

A commit records a snapshot of the staged changes in the repository history.

TERMINAL

Create a Commit

git commit -m "Add contact page"

The message should briefly describe the purpose of the change. Compare these two messages:

Less Helpful

Update files

More Helpful

Add contact form validation

Clear commit messages make the project history easier to understand later.

It is also usually easier to understand a history made of focused commits than one enormous commit containing several unrelated changes.

07

How Does a Local Repository Connect to GitHub?

A repository on your computer is local. A repository hosted elsewhere, such as on GitHub, can be configured as a remote.

A common remote name is origin.

TERMINAL

Add a Remote

git remote add origin <repository-url>

Replace <repository-url> with the appropriate remote repository URL.

You can inspect configured remotes with:

TERMINAL

View Remotes

git remote -v

Authentication may be handled differently depending on whether you use HTTPS, SSH, a credential manager, or a development environment with GitHub integration.

08

Understand Clone, Pull, and Push

These commands are commonly used when working with remote Git repositories.

CommandMain Purpose
git cloneCreate a local copy of an existing repository
git pullFetch remote changes and integrate them into the current branch
git pushSend local commits to a configured remote repository
TERMINAL

Clone a Repository

git clone <repository-url>
TERMINAL

Pull Remote Changes

git pull
TERMINAL

Push Local Commits

git push

Git commands depend on the repository's current branch, remote configuration, and upstream tracking. If a command does not behave as expected, check the repository state rather than repeatedly rerunning it.

09

What Is a Git Branch?

Branches allow development to proceed along separate lines without immediately changing another branch.

For example, you might create a branch for a new contact page while keeping the main branch unchanged until the work is ready.

TERMINAL

Create and Switch to a Branch

git switch -c contact-page

To see your local branches:

TERMINAL

List Branches

git branch

To switch to an existing branch:

TERMINAL

Switch Branch

git switch main

Older tutorials may use git checkout for some branch operations. You may therefore encounter both commands while working with existing projects or documentation.

10

What Is a Pull Request?

A pull request is a GitHub collaboration feature used to propose changes from one branch for review and possible integration into another branch.

A common workflow might look like this:

1

Create a branch for the change.

2

Edit the project and test the work.

3

Stage and commit the changes.

4

Push the branch to GitHub.

5

Open a pull request.

6

Review the differences and any automated checks.

7

Resolve issues if necessary and merge when the change is ready.

Pull requests are particularly useful for team projects because they create a clear place to discuss and review proposed changes before integration.

11

Common Git & GitHub Mistakes

1. Assuming saving a file creates a commit

Saving updates the file on your computer. Git does not create a new commit until you stage the intended changes and commit them.

2. Assuming a commit automatically appears on GitHub

A local commit remains in your local repository until it is pushed to the appropriate remote branch.

3. Running commands without checking the current branch

Before committing, pulling, merging, or pushing, make sure you understand which branch you are currently working on.

4. Committing secrets

Passwords, private keys, API credentials, access tokens, and sensitive configuration should not be committed to a repository.

Removing a secret from the latest file is not enough

If a credential has already been committed, it may still exist in repository history. Treat an exposed credential as compromised, rotate or revoke it where appropriate, and then address the repository history separately.

5. Committing unnecessary generated files

Dependencies, build output, temporary files, environment files, and editor-specific files may not belong in version control. A .gitignore file can tell Git which matching untracked files should normally be ignored.

6. Using unclear commit messages

Messages such as “stuff,” “changes,” or “final final” make the project history harder to understand. Describe the purpose of the change.

7. Using destructive commands without understanding them

Some Git operations can discard local changes or rewrite history. Do not copy a reset, clean, rebase, or force-push command simply because it appears in a troubleshooting answer. Understand its effect first.

12

Beginner Git Command Checklist

You do not need to memorize every Git command immediately. Start by understanding what these common commands do:

CommandPurpose
git initInitialize a repository
git cloneCopy an existing repository locally
git statusInspect the current repository state
git addStage changes for a commit
git commitRecord staged changes in repository history
git branchInspect or manage branches
git switchSwitch branches or create and switch to one
git pullFetch and integrate remote changes
git pushSend local commits to a remote

More important than memorizing commands is understanding the state of the repository before you run them.

1

Which repository am I working in?

2

Which branch am I currently on?

3

Which files have changed?

4

Which changes are staged?

5

Which changes have been committed?

6

Is a remote repository configured?

7

Have my local commits been pushed?

WORKING WITH GIT OR GITHUB?

Stuck With a Repository or Project Workflow?

Share the Git command, error message, repository state, and what you were trying to accomplish. The issue can then be worked through in the context of your actual project.

Get Programming Support