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

For everyday Git work, learn a short loop: check the repository with git status, inspect changes with git diff, stage selected content with git add, review the staged version, then save it with git commit. Use branches to isolate work, and fetch remote updates before integrating them when you want to review first.

What Git records—and what staging means

Git records project snapshots as commits. A branch is a movable name for a line of work, which lets you develop changes separately before integrating them. The Git user manual describes Git as “a fast distributed revision control system.” Git user manual

Before a commit, Git uses an index—also called the staging area—to select the content that will go into the next snapshot. git add <path> stages that path’s content as it exists at that moment. If you edit the file again, run git add again to stage the newer content.

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.

Start with a repository

  • git --version prints the installed Git version.
  • git init creates a repository in the current directory.
  • git clone <url> creates a local copy of an existing repository.

Use git init when beginning a repository in a directory you already have; use git clone when you need a local copy of an existing one.

Inspect, stage, and commit changes

For a typical change, run these commands from inside the repository:

git status
git diff
git add <file>
git diff --cached
git commit -m "Describe the change"
git show
  1. git status summarizes changes in the working tree and index, including files Git does not yet track.
  2. git diff shows working-tree changes that are not staged.
  3. git add <file> selects a file’s current content for the next commit. Use a path for a specific file; to stage all changes under the current directory, use git add . and review the result carefully.
  4. git diff --cached shows what is staged compared with the current commit.
  5. git commit -m "Describe the change" records the staged content with a message.
  6. git show displays the latest commit and its changes by default, so you can verify what was recorded.

The three diff forms answer different questions:

Command Comparison What it tells you
git diff Working tree versus index What is changed but not staged.
git diff --cached Index versus HEAD What the next commit would include, compared with the current commit.
git diff HEAD Working tree versus HEAD All current tracked changes relative to the current commit, whether staged or not.

For a new file, use git add before committing: it is untracked until staged. The shortcut git commit -a -m "Describe the change" stages modifications and removals to already tracked files, but it does not include new untracked files. Explicitly staging and reviewing is easier to audit when you want precise control over a commit.

Create a branch and merge finished work

Branches let you work on a feature or fix without immediately changing another line of work. Branch names vary by repository; do not assume the base branch is called master.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git branch
git switch -c <topic-branch>
# edit, inspect, stage, and commit
git switch <base-branch>
git merge <topic-branch>
  1. git branch lists local branches. It can also create a branch, but does not switch to it.
  2. git switch -c <topic-branch> creates a branch and switches to it.
  3. Make and commit changes on the topic branch using the inspect-stage-commit workflow.
  4. git switch <base-branch> returns to the branch that should receive the work.
  5. git merge <topic-branch> integrates the named branch into the branch you are currently on.

If Git reports conflicts during a merge, it cannot automatically reconcile some changes. Resolve the marked files, review them, and complete the merge as Git requests; do not assume every merge is conflict-free.

Update from and share with a remote

A remote is another copy of the repository, commonly hosted on a server. Check configured remotes with git remote -v. Remote-tracking branches record the state Git last learned from a remote; they do not update until you fetch.

Fetch and inspect before integrating

git fetch
git log --oneline --decorate --graph --all
git merge <remote>/<branch>

git fetch updates remote-tracking information without integrating those commits into your current branch. Review the graph or inspect the relevant commits, then explicitly merge the remote-tracking branch you intend to integrate. Replace <remote> and <branch> with the names used by your repository.

Use pull as the one-step shortcut

git pull fetches and then integrates updates according to the current branch’s configured upstream and Git settings. That integration may use a merge or another configured strategy, such as rebase; it does not mean “merge every remote change.” A pull can encounter conflicts, so check git status afterward and resolve any Git-reported issues before continuing.

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

Push local commits

git push sends local commits to a remote. A first push may require setting an upstream branch, depending on the repository and Git configuration. If Git reports that no upstream is set, follow the command it suggests or consult git help push for the applicable options.

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

Commands to treat with care

git reset --hard resets the working tree and index to a specified state, discarding uncommitted changes in the process. Depending on the target, it can also move the current branch so that a prior commit is no longer reachable through that branch. Do not use it as a casual undo command: first check git status, preserve anything you may need, and understand which commit you are resetting to.

Find help for a specific command

Command options and preferred syntax can vary by Git version. Use git help <command>, such as git help switch, for the installed documentation, or consult the Git project’s current command reference. The official everyday command guide is useful for its task-based overview, while the current manual is the better place to verify exact behavior.

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.

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