Software Development
ABC of Git Commands – Version Control System
3647
ABC of Git Commands is a beginner-friendly way to understand the most common Git commands used in version control. Git helps developers track changes, manage branches, save updates, and work with code more confidently.
Git is a free and open-source distributed version control system. It works well for small projects, large applications, and team-based development.
| Letter | Git Command | Purpose |
|---|---|---|
| A | Add | Add file changes to the staging area |
| B | Branch | Create or manage separate code branches |
| C | Commit and Checkout | Save changes and switch between branches |
Before learning these commands, let’s first understand what version control means.
A version control system helps track changes made to files over time. It shows what changed, when it changed, and who made the update.
This is very useful when more than one person works on the same project. Without version control, code changes can become difficult to manage. Also, it becomes harder to find mistakes or restore older versions.
Git solves this problem by keeping a complete history of file changes. As a result, developers can work safely, test new ideas, and manage project updates with better control.
You can install Git based on your operating system.
| Operating System | Installation Method |
|---|---|
| Windows | Download the Windows installer from the official Git website. |
| macOS | Download the Mac installer or install Git using a package manager. |
| Linux | Install Git using your system package manager based on your Linux distribution. |
After installation, you can use Git from the command line, terminal, or code editors like Visual Studio Code.
The git add command moves file changes to the staging area.
The staging area works like a preparation area before saving changes permanently in Git history. First, you select the files. Then, you commit them with a message.
To add all changed files, use:
git add .
To add a specific file, use:
git add {file_name}
Example:
git add index.html
This command tells Git that the selected file is ready for commit.
A branch helps you work on a separate version of your code.
For example, you may create a new branch for a login feature, bug fix, or design update. Meanwhile, your main branch stays safe and unchanged.
To view all local branches, use:
git branch
To create a new branch, use:
git branch {branch_name}
Example:
git branch feature-login
To delete a local branch, use:
git branch -d {branch_name}
Example:
git branch -d feature-login
To delete a remote branch, use:
git push origin --delete branch-name
Branches make Git powerful because they help developers work in a clean and organized way.
In this blog, C includes two important Git commands:
git commitgit checkoutBoth commands are common in day-to-day Git usage.
The git commit command saves staged changes in Git history.
A commit should always include a clear message. This message explains what change you made.
To commit changes with a message, use:
git commit -m "Your commit message"
Example:
git commit -m "Added login page design"
A good commit message helps you and other developers understand the purpose of the update later.
The git checkout command helps you switch between branches.
To switch to an existing branch, use:
git checkout {branch_name}
Example:
git checkout main
To create a new branch and switch to it, use:
git checkout -b {branch_name}
Example:
git checkout -b feature-dashboard
This command saves time because it creates the branch and moves you to it immediately.
Apart from add, branch, commit, and checkout, beginners should also know a few more Git commands.
| Command | Purpose |
|---|---|
git status |
Check changed, staged, and unstaged files |
git push |
Send committed changes to the remote server |
git pull |
Get the latest changes from the remote branch |
git stash |
Temporarily save uncommitted changes |
git stash pop |
Bring back stashed changes |
git reset --hard |
Discard local changes |
The git status command shows the current state of your working directory.
git status
It helps you check which files changed and which files are ready for commit.
In many terminals, red files usually show changes that are not staged yet. Green files usually show changes that are staged but not committed yet.
The git push command sends committed changes to the remote Git server.
git push origin {branch_name}
Example:
git push origin main
After pushing the changes, other team members can access them from the remote repository.
The git pull command gets the latest changes from the remote branch.
git pull
It is a good practice to pull the latest code before starting new work. This helps reduce conflicts and keeps your local code updated.
The git stash command temporarily saves your uncommitted changes.
git stash
This is helpful when you want to switch branches but do not want to commit incomplete work.
To bring back stashed changes, use:
git stash pop
The git reset --hard command discards local changes.
git reset --hard
Use this command carefully. It can remove your local changes permanently.
Sometimes, two developers update the same file and change the same lines of code. In that situation, Git may show a merge conflict.
A merge conflict means Git needs your help to decide which changes should stay. You need to review the conflicting lines and choose the correct version.
We will cover Git conflicts and conflict resolution in the next blog.
Git is an essential tool for managing code changes. It helps developers track updates, create branches, save work, and collaborate more safely.
For beginners, the best starting point is to understand git add, git branch, git commit, and git checkout. After that, commands like git status, git push, git pull, git stash, and git reset --hard become easier to use in real projects.