Useful Git Commands for Everyday Development
Git is a distributed version-control system used to track changes in files and coordinate work across branches and repositories. Developers use it to create commits, experiment with features, review history, and collaborate with other people.
Remembering every command and option can be difficult, especially when a task is performed only occasionally. The iamnoobs Git Command Generator helps you find common command templates, fill in placeholders, and copy the resulting command.
This guide explains useful commands and highlights operations that need extra care.
Start with the basic workflow
A typical local change may follow this sequence:
git status
git add src/example.js
git commit -m "Add example feature"
git push
The commands have different purposes:
- git status shows the working tree and staging state.
- git add places selected changes in the staging area.
- git commit records the staged snapshot in the local repository.
- git push sends local commits to a remote repository.
Review what is staged before creating a commit. Avoid using git add . automatically when unrelated files or generated secrets may be present.
Create and switch branches
Branches let you work on a line of development without changing the branch currently checked out.
Create a new branch and switch to it:
git switch -c feature/search
The older command is also widely used:
git checkout -b feature/search
List local branches:
git branch
Switch to an existing branch:
git switch main
A branch is a movable reference to a commit. Creating a branch does not copy the entire repository.
Save unfinished work with stash
Sometimes you need to switch branches but are not ready to commit your current changes.
git stash push -m "Work in progress"
This saves eligible working-tree changes in a stash entry. To reapply the latest entry and remove it from the stash list:
git stash pop
To see available entries:
git stash list
Stash is useful for short-lived context switches, but it is not a substitute for regular commits or backups. Review untracked-file behavior and options when you need to include new files.
View commit history
A compact history is useful when reviewing recent work:
git log --oneline --decorate -10
To inspect the changes introduced by a commit:
git show <commit>
To compare the working tree with the staging area:
git diff
To inspect staged changes before committing:
git diff --staged
These commands help you verify exactly what will be included in the next commit.
Merge and rebase
Both merge and rebase integrate work from another line of development, but they do it differently.
Merge combines histories and may create a merge commit:
git switch main
git merge feature/search
Rebase replays commits on top of another base:
git switch feature/search
git rebase main
Rebase can produce a linear history, but it rewrites commit identities. Avoid rebasing commits that other collaborators already depend on unless your team has agreed on that workflow.
Generate common commands with the online tool
- Open the iamnoobs Git Command Generator.
- Search for a task such as branch, merge, stash, or clone.
- Fill in the displayed placeholders.
- Review the generated command carefully.
- Copy it and inspect the command in your terminal before executing it.
The generator provides templates for common operations such as creating and deleting branches, merging, rebasing, stashing, cherry-picking, resetting, cloning, adding remotes, and viewing history. It generates text; it does not execute Git commands on your computer.
Commands that need special care
Some Git commands can discard work or change shared history.
git reset --hard
git reset --hard <commit>
This moves the current branch reference and resets the index and working tree to the specified commit. Uncommitted tracked changes can be lost. Do not run this command as a routine cleanup step.
Before considering a reset, inspect your state:
git status
git log --oneline -5
git diff
git diff --staged
Create a commit, stash, or backup when you need to preserve work.
Force pushing
The generator includes a force-with-lease command template:
git push --force-with-lease
This is safer than an unconditional force push in that Git checks the remote reference against the expected remote-tracking state. It can still replace remote history. Coordinate with collaborators and inspect the branch before using it.
Deleting a remote branch
git push origin --delete feature/search
This removes the named branch from the remote repository. Confirm the branch is no longer needed and has been merged or backed up before deleting it.
Resetting commits
Commands such as git reset --soft, git reset, and git reset --hard differ in what they do to the index and working tree. Understand the specific mode before using it.
Useful commands at a glance
| Task | Command |
|---|---|
| Check working tree | git status |
| Stage one file | git add path/to/file |
| Commit staged changes | git commit -m "Message" |
| Create and switch branch | git switch -c branch-name |
| List branches | git branch |
| View compact history | git log --oneline |
| View unstaged changes | git diff |
| View staged changes | git diff --staged |
| Save work temporarily | git stash push -m "message" |
| Reapply and remove latest stash | git stash pop |
| Download remote updates | git fetch |
| Send commits to a remote | git push |
Common Git mistakes
1. Forgetting to check status
Run git status before staging, committing, or switching branches. It helps identify modified, staged, untracked, and conflicted files.
2. Assuming add means commit
git add stages content. It does not create a commit or send anything to a remote repository.
3. Rebasing shared history without agreement
Rebase creates new commit IDs. Rewriting a branch that collaborators use can make synchronization confusing and may require recovery work.
4. Running destructive commands without a backup
Always inspect the target commit and current changes before using reset, clean, or branch deletion commands.
Frequently asked questions
Does the Git Command Generator execute commands?
No. It creates command text and provides a copy action. You decide whether to run the command in your own repository.
Is git reset the same as git revert?
No. Reset moves a branch reference and may change the index and working tree. Revert creates a new commit that records the inverse of an earlier change. Revert is commonly preferred when undoing a change already shared with others.
What is the difference between fetch and pull?
Fetch downloads remote references and objects without integrating them into the current branch. Pull generally performs a fetch followed by an integration step, such as merge or rebase depending on configuration.
Further reading
Try it: iamnoobs Git Command Generator