Essential Git Commands for Developers: Checking, Reverting, Cleaning, and Customizing the Workflow
This article introduces ten essential Git commands—including diff, log, reset, revert, clean, and commit‑amend—explains how to escape Vim, change the default editor, and create Bash aliases for faster Git operations, providing practical examples and code snippets for developers.
The article presents a concise guide to the most useful Git commands that developers, data scientists, and product managers should know, covering inspection, undoing changes, cleaning untracked files, organizing commits, and customizing the Git environment.
Inspection
git diff – view changes in all local files or a specific file.
git log – display commit history; use git log -p my_file for a file’s diff and press q to quit.
git blame my_file – show who changed each line and when.
git reflog – list the HEAD reference log, useful for finding lost work.
Undoing Changes
git reset --hard HEAD – discard all changes since the last commit.
git checkout my_commit – revert un‑staged changes to a specific commit; also switches branches when a branch name is given.
git revert my_commit – create a new commit that undoes the changes introduced by my_commit , safe for shared history.
Use git reset or git checkout for local, un‑pushed changes; use git revert when you need to undo a commit that has already been shared.
Cleaning Untracked Files
git clean -n – dry‑run; shows what would be removed without deleting.
git clean -f – actually delete untracked files.
git clean -d – delete untracked directories as well.
By default, files ignored via .gitignore are not removed, but this behavior can be changed.
Organizing Commits
git commit --amend – add staged changes to the most recent commit or edit its message (only before the commit is pushed).
git push my_remote --tags – push all local tags to the remote repository.
Escaping Vim
If Git opens Vim (e.g., when committing without a message), you can exit with four steps:
Press i to enter insert mode.
Type your commit message on the first line.
Press Esc to leave insert mode.
Enter :x and press Enter to save and quit.
Changing the Default Editor
To avoid Vim, set another editor (e.g., Atom) as the default:
git config --global core.editor "atom --wait"After installing Atom, Git will launch it for commit messages.
Creating Git Command Shortcuts
Add aliases to .bash_profile for faster access:
alias gs='git status '
alias ga='git add '
alias gaa='git add -A '
alias gb='git branch '
alias gc='git commit '
alias gcm='git commit -m '
alias go='git checkout 'If .bash_profile does not exist, create it and open it:
touch ~/.bash_profile
open ~/.bash_profileThese aliases let you type gs instead of git status , and similarly for other common commands.
Conclusion
The guide equips readers with key Git commands, environment configuration tips, and shortcut techniques to streamline version‑control workflows and improve productivity.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.