Labs ICT
Pro Login

10 Git Commands Every Developer Must Know

General Tools 6 min read

The essential Git commands for everyday development. A practical guide to the workflow commands you will use in every project.

Git is Non-Negotiable

If you are a developer and you are not using Git, you are making your life harder than it needs to be. Git tracks every change to your code, lets you experiment without fear, and enables collaboration with other developers. These ten commands cover 90% of what you will use daily.

1. git init

This initializes a new Git repository in your project folder. Run it once at the start of a new project and Git starts tracking your files. All your future commits will be stored in the .git folder that gets created.

You only run this once per project. After that, all other Git commands work within this repository.

2. git add

This stages changes for commit. Think of it as putting files in a waiting area before you permanently save them. You can stage specific files with git add filename or stage everything with git add .

Staging lets you choose exactly what goes into a commit. This is useful when you have made multiple changes but want to save them in separate, logical commits.

3. git commit

This saves your staged changes with a message describing what you did. The format is git commit -m "your message here". Write messages that explain why you made the change, not just what changed.

Good commit messages are future-you's best friend. When you look at your project history in six months, clear messages save you from reading every line of code to understand what happened.

4. git status

This shows you the current state of your repository. It tells you which files are modified, which are staged, and which are untracked. Run this often. It is your compass when working with Git.

If you are ever unsure what Git is doing, run git status first. It will almost always tell you what you need to know.

5. git push

This uploads your local commits to a remote repository like GitHub. The basic command is git push origin main, which pushes your main branch to the remote called origin.

Push your code regularly. Do not wait until you have hundreds of changes. Small, frequent pushes keep your remote repository up to date and make collaboration smoother.

6. git pull

This downloads and integrates changes from the remote repository into your local code. It is the opposite of git push. Run git pull before you start working to make sure you have the latest changes.

Pulling regularly prevents merge conflicts. The longer you go without pulling, the more likely you are to have conflicts when you finally do.

7. git branch

Branches let you work on new features without affecting the main code. Create a branch with git branch feature-name and switch to it with git checkout feature-name or use the shorthand git checkout -b feature-name to do both at once.

The workflow is simple: create a branch for each feature, work on it independently, then merge it back to main when it is ready. This keeps your main branch stable.

8. git merge

This combines changes from one branch into another. After you finish working on a feature branch, you merge it back to main with git checkout main followed by git merge feature-name.

Merge conflicts happen when two branches change the same file. Git will ask you to manually resolve the conflicts. Do not panic when this happens. Look at the conflicting sections, decide which changes to keep, and save the file.

9. git log

This shows the history of commits in your repository. The basic command shows all commits, but you can use git log --oneline for a compact view or git log --graph to see branch history visually.

Git log is useful for finding when a bug was introduced, understanding the evolution of a feature, or simply reviewing what you accomplished today.

10. git clone

This creates a copy of a remote repository on your machine. When you want to work on an existing project, you clone it with git clone repository-url. This downloads all the code and the entire commit history.

You will use git clone every time you start working on a new project that already has a remote repository on GitHub or another hosting service.

The Daily Workflow

Here is a typical daily workflow using these commands: pull the latest changes, create a branch for your feature, make your changes, add and commit them, push the branch, and create a pull request. Once reviewed, merge it to main.

Master these ten commands and you will handle almost every Git situation you encounter. The rest of Git is useful but rarely needed for everyday development.