Skip to main content

Command referencegit

git command (Linux / bash / sh / zsh)

Linuxbashshzshgitintermediate

What it does

Track source history and collaborate through distributed repositories. When people search for the git command linux version control, they usually want git's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Track source history and collaborate through distributed repositories.

Syntax

git [OPTION] COMMAND [ARGS]

Common options

Flag / optionMeaning
statusShow working-tree and index state.
addStage content for the next commit.
commitRecord staged changes.
logShow commit history.
switchChange or create branches.

Practical examples

Inspect changes

git status --short

Shows concise repository state.

Create commit

git add src && git commit -m 'Update source'

Stages src and records a commit.

New branch

git switch -c feature/search

Creates and checks out a feature branch.

Common mistakes

  • Committing secrets or generated build artifacts.
  • Using destructive reset or clean commands without checking status and backups.

FAQ

What does git do in Linux?

Track source history and collaborate through distributed repositories.

How do I use git from the terminal?

Start with `git [OPTION] COMMAND [ARGS]`, then choose only the options needed for the task.

What is a practical git example?

Try `git status --short` — Shows concise repository state.

Can I use git in a shell script?

Yes. git works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.