git command (Linux / bash / sh / zsh)
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 / option | Meaning |
|---|---|
| status | Show working-tree and index state. |
| add | Stage content for the next commit. |
| commit | Record staged changes. |
| log | Show commit history. |
| switch | Change 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.
Related commands
- historyDisplay or modify the current shell's command history.
- whichLocate the executable selected from the current PATH.
- dockerBuild images and manage containers, networks, and volumes.
- gh auth loginAuthenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
- gh pr createCreate a pull request from the current branch with title, body, reviewers, and base branch options.
- gh pr mergeMerge a pull request using merge commit, squash, or rebase strategies.
- gh repo cloneClone a GitHub repository to your machine using your authenticated gh settings.
- gh pr checkoutCheck out a pull request locally as a branch so you can build, test, or review the changes.
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.