Master Git: Essential Commands Every Developer Should Know

Recent graduate with a Master’s degree in Information Systems from the University of Portsmouth, United Kingdom. Passionate about leveraging technology to solve real-world problems, with hands-on academic in Linux system management, cloud computing (AWS), application support, and automation using Bash .Also Development, debugging and providing production support .
Programming Language: Java
Framework: Spring boot
Operating Systems: Linux, Windows
Container: Docker (Basic)
Cloud Platforms: AWS
Scripting Languages: Bash shell
Monitoring & Logging: Grafana
Version Control: Git
Databases: MySQL , Oracle
Ticketing tool: JIRA
Hands-on experience with web servers like Nginix and Apache tomcat.
Hands-on experience with UAT/SIT and production deployments.
Whether you're just starting with Git or want a reliable reference guide, this blog breaks down the most essential Git commands, what they do, and how to use them — all in one place. Let’s dive in!
Version Check
Check the installed Git version.
git --version
Repository Setup
Initialize a new Git repository in your current directory.
git init
Staging Files
Stage a specific file for commit.
git add index.html
Stage all modified and new files.
git add .
Removing Files
Remove a file from the working directory and staging area.
git rm old_script.js
Committing Changes
Commit staged changes with a message.
git commit -m "Fix navbar bug"
Viewing History
View commit history in detail.
git log
Compact view: one commit per line.
git log --oneline
Display changes and metadata for a specific commit.
git show 3a1f4d2
Show who last modified each line of a file.
git blame app.js
Status Check
View current changes, staged files, and untracked files.
git status
Undo & Revert
Reset your working directory to a specific commit, removing changes.
git reset --hard 3a1f4d2
Undo a commit by creating a new one that reverses it.
git revert 3a1f4d2
Remote Management
List all configured remotes.
git remote
Pushing Code
Push changes to the current branch on the remote.
git push
Force push — overwrites remote history. Use with caution!
git push -f
Set the upstream (remote tracking) branch for a new local branch.
git push --set-upstream origin new-feature
Branching
List, create, or delete branches.
git branch # List branches
git branch featureX # Create new branch
Switch to another branch.
git checkout main
Create and switch to a new branch.
git checkout -b bugfix/login-issue
Merging & Rebasing
Merge a remote branch into your current branch.
git merge origin/new-feature
Reapply commits on top of another branch — cleaner history.
git rebase main
Temporary Changes
Save uncommitted changes temporarily.
git stash
Reapply the latest stashed changes.
git stash apply
Generating SSH Keys and Connecting GitHub via SSH
To securely connect your local Git with GitHub, you can use SSH authentication instead of typing your username and password every time. First, you’ll need to generate a public-private key pair. You can do this by running the command ssh-keygen -t ed25519 -C "your_email@example.com" in your terminal, replacing the email with the one linked to your GitHub account. When prompted, just press Enter to accept the default location for saving the key.
After the key is generated, you need to add it to the SSH agent so your system can use it automatically. Start the agent with eval "$(ssh-agent -s)" and then add your key using ssh-add ~/.ssh/id_ed25519.
To connect this key to GitHub, copy the contents of your public key by running cat ~/.ssh/id_ed25519.pub and copying the entire output. Then, go to your GitHub account, navigate to Settings > SSH and GPG keys, click “New SSH key”, paste the key, and save. Now your machine is authenticated with GitHub, and you can push and pull securely without entering your credentials each time.
Git Branch Naming Conventions
Using consistent and descriptive branch names helps keep your Git repository organized, especially when working in teams. A common convention is to use a format like type/short-description, which quickly tells you the purpose of the branch.
For example, branches for new features are often named with the feature/ prefix, like feature/login-page. Bug fixes might use bugfix/, such as bugfix/navbar-issue. Urgent production fixes typically go under hotfix/, for example, hotfix/crash-on-startup. Release branches follow a versioning pattern like release/v2.0.0, and minor tasks or maintenance can use chore/, such as chore/clean-temp-files. You can also use docs/ for documentation updates and test/ for testing-related branches.
The general best practice is to keep branch names lowercase, use hyphens for readability, and avoid including personal names unless necessary. Clear, consistent naming makes collaboration smoother and helps tools like CI/CD pipelines work more effectively.
