Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To save work in Git, inspect your project with git status, stage the files you want included with git add, and record that staged snapshot with git commit. To share commits, connect the repository to a remote host and use git push. This guide walks through that workflow and explains how to check what each command will do.

Understand the three places Git tracks work

Git separates your project into a working tree, a staging area (also called the index), and commit history. Files you edit are in the working tree. Staging selects the content for the next commit. A commit records that selected snapshot on the current branch.

This separation is useful: you can edit several files but stage only the finished changes you want to save together. The official Git user manual is written for readers with basic command-line familiarity and no prior Git knowledge.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check Git and set your commit identity

Open a terminal and check which Git version is installed:

git --version

Before creating commits, configure the author name and email if Git asks for them or they are not already set:

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

These values are recorded as commit author information. You do not have to use a personal email address; if you use a hosting service, check whether it offers a privacy-preserving commit address.

Start a repository: initialize or clone

Choose the command based on where the project already exists:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Situation Command What it does
You have a local project that is not yet tracked by Git git init Creates an empty Git repository in the current directory.
The repository already exists on a remote host git clone <repository-url> Copies the repository to your computer and normally configures tracking for its default branch.

To initialize an existing local project, move into its directory first:

cd path/to/project
git init

For a project that already exists remotely, clone it instead of initializing a separate repository. The official git init manual explains repository creation and initial-branch configuration; the Git book’s repository overview covers both ways to get a repository.

Do not assume the initial branch is always named main or master. Its name depends on Git version and configuration. Check it with git branch --show-current or inspect the branch shown by git status.

Inspect changes before choosing what to save

Make git status your orientation command. It summarizes the repository state, including the current branch and changes that are not yet committed:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git status

Use git diff to inspect edits in the working tree that have not been staged:

git diff

After staging, use git diff --cached to inspect what is selected for the next commit. The distinction is important: git diff shows unstaged work, while git diff --cached compares staged content with the current commit.

Stage selected files, then verify the selection

Stage a named file while learning, then check the status again:

git add README.md
git status

Staging records the file’s current contents in the index. If you edit that file again afterward, stage it again to include the later edit in the next commit. You can stage several named files by listing them in one command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

git add . stages changes under the current directory, which can include more files than you intended. Before using it, check your current directory and git status; staging named files gives you more control.

Commit a clear snapshot

Once the staged changes look right, review them and create a commit with a short message describing the change:

git diff --cached
git commit -m "Add project overview"
git log --oneline

A commit records the staged snapshot on the current branch. Focused commits with descriptive messages are easier to understand and revisit than one large commit labeled only “changes.” Use git show to inspect a commit’s details. The everyday Git guide summarizes the role of core commands, and the user manual explains the index and commit workflow.

Use a branch to keep separate work apart

A branch is a line of development. Create and switch to a branch for a separate task with git switch -c:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git switch -c add-contact-page

Make the changes, review and commit them, then switch back to the original branch. Replace main below with the branch name actually used by your repository:

git status
git add path/to/changed-file
git commit -m "Add contact page"
git switch main

Run git status before switching if you have uncommitted work, so you can see what remains in the working tree. The Git user manual documents creating a branch with git switch -c and changing branches with git switch.

Check the remote before pulling or pushing

Git is the version-control tool; GitHub, GitLab, and other hosting services provide places to store remote repositories and collaborate. A remote is a named reference to another repository. If you cloned a project, a remote is commonly configured already. Check its name and address with:

git remote -v

git pull obtains changes from an upstream branch and integrates them into your current branch. git push sends local commits to a remote branch. Which branch these commands use by default depends on the repository’s upstream configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git pull
git push

A clone normally configures upstream tracking for its default branch. A repository you created with git init may need a remote added and an upstream set before a plain push works. When you need to establish tracking for a new branch, the documented form is:

git push --set-upstream origin <branch>

Here, origin is the conventional remote name, but use the name shown by git remote -v if yours differs. The git pull manual describes upstream behavior, and the git push manual covers pushing commits and fast-forward requirements.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a push fails, inspect before changing history

A rejected push can mean the remote branch has commits you do not have, or your local branch is not tracking the intended upstream. Do not reflexively force-push: rewriting a remote branch can make commits unreachable from named branches.

  • Run git status to identify the current branch and any uncommitted changes.
  • Run git branch --show-current to confirm which branch you are pushing.
  • Run git remote -v to confirm the remote destination.
  • Check whether the branch has an upstream; if not, set one with git push --set-upstream origin <branch>, using the actual remote and branch names.
  • If the remote contains work your local branch lacks, integrate that work according to your project’s workflow before trying to push again.

The push manual explains why non-fast-forward updates are rejected and the risks of making commits unreachable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A compact first-session workflow

For an existing local folder, this is the complete basic cycle. Review each status and diff before committing; substitute a real file and a message that describes your change.

cd path/to/project
git init
git status
git add README.md
git status
git diff --cached
git commit -m "Add project overview"
git log --oneline

For a project already hosted remotely, begin with git clone <repository-url> and work inside the cloned directory. Once you have commits to share, check the remote and branch configuration before pushing.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.