The everyday Git workflow: status, add, commit, push, pull
Git moves your changes through three places: the working folder, the staging area, and the commit history. These five commands, plus .gitignore and stash, cover most daily work.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
Git does not save every keystroke. You decide what goes into each snapshot, called a commit. To do that, Git keeps your work in three places:
- Working tree: the files you see and edit.
- Staging area (also called the index): the changes you have picked for the next commit.
- Repository: the saved commits. A remote such as GitHub holds a copy you share with others.
The daily loop
git switch main
git pull # get what others pushed
# ...edit files...
git status # what changed?
git diff # exact lines, not yet staged
git add app.py # stage one file (git add . stages everything)
git diff --staged # what the commit will contain
git commit -m "Add greeting to the home page"
git push # share it
git status is the command to run whenever you are unsure. git status --short gives one line per file: ?? means untracked (Git has never seen it), M in the right column means modified but not staged, and a letter in the left column means staged.
Staging lets you split work into focused commits. If you fixed a bug and also renamed a variable, stage and commit them separately. git add -p goes further and asks about each changed hunk.
Write commit messages that finish the sentence “This commit will…”: Fix crash when the cart is empty tells a reviewer far more than fixes.
Keep files out with .gitignore
Some files should never be committed: dependencies you can reinstall, build output, logs, and anything holding secrets. List them in a file named .gitignore at the root of the project and commit that file.
node_modules/
dist/
*.log
.env
.DS_Store
A trailing / matches a folder, * matches anything, and a line starting with ! re-includes something an earlier line excluded. To find out which rule hides a file, ask Git:
git check-ignore -v .env
.gitignore only affects files Git is not tracking yet. If a file is already committed, stop tracking it while keeping it on disk:
git rm --cached .env
git commit -m "Stop tracking .env"
If that file held a password or API key and was ever pushed, treat the secret as leaked and replace it. Removing the file from later commits does not remove it from history.
Park unfinished work with stash
Need to switch branches but not ready to commit? git stash saves your uncommitted changes and gives you a clean working tree.
git stash push -m "half-done search box"
git stash push -u -m "including new files" # -u also saves untracked files
git stash list
git stash pop # re-apply the newest stash and remove it
git stash apply stash@{1} # re-apply but keep it in the list
git stash drop stash@{1}
Stashes are easy to forget. If you will be away from the work for more than a few hours, a commit on a branch is the safer place for it.
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0032 First-time Git setup: name, email, default branch, SSH or HTTPS Tell Git who you are, pick sensible defaults, and choose between SSH and HTTPS for GitHub. Includes a small script that applies… Beginner · Step by step · Linux, macOS, Windows Script Setup 15 Oct 2026
- 0043 Delete local branches that are already merged A bash script that lists local branches fully merged into main and, if you ask, deletes them. It never touches the current… Intermediate · Step by step · Linux, macOS, Windows Script Housekeeping 15 Oct 2026
- 0262 Make your first pull request: Git and GitHub from first commit to merged change A complete beginner's path through Git and GitHub: set up Git, make commits, ignore files, use branches, push to GitHub, open a… Beginner · Guided project · Any system Article Branching & rebasing · Pull requests · Setup 15 Oct 2026
- 0318 Fix: fatal: not a git repository Git looked in the current directory and every parent for a .git folder and found none. You are in the wrong directory,… Beginner · Fixes an error · Any system Article Common errors · Setup 15 Oct 2026
- 0357 Keep secrets out of git: .env files, gitignore and what to do after a leak Load passwords and API keys from an untracked .env file, commit a safe .env.example instead, catch mistakes before they are pushed, and… Beginner · Step by step · Any system Article Housekeeping · Secrets & access 15 Oct 2026
- 0381 pre-commit hooks: catch mistakes before they are committed Install the pre-commit framework, configure hooks for whitespace, YAML and JSON syntax, large files, leaked private keys, Python linting and shellcheck, run… Beginner · Step by step · Linux, macOS, Windows Article Pipelines, runners & hooks · Setup 15 Oct 2026
Repos in the wild
- git-extras tj/git-extras A collection of extra Git subcommands for common chores, such as summarizing a repository, deleting merged branches, and undoing commits. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +2,881 chars