Git commands: practical guide for developers
Tips 'n tricks about the web, digital trends, and online marketing
Git commands, the backbone of modern software development
At Funkhaus, we build websites, web apps and smart marketing flows every day. In these, we rely on Git to securely record our work, collaborate smoothly and revert to a previous version without risk when needed.
In this knowledge base article, we will take you through what exactly Git is, what you use it for and why it is so important in the way we work. Then we share a comprehensive list of useful Git commands, including examples and tips that we apply ourselves in our projects.
What is Git?
Git is a distributed version control system: each developer has local access to the complete code history. This makes operations such as commits, diff and branch management extremely fast and reliable. Instead of one central source, you keep local snapshots (commits) that you can later push to a remote such as GitHub, GitLab or Bitbucket. For a full reference, check out Git's official documentation and the free book Pro Git.
Why do you use Git and why is it important?
Git makes collaboration predictable: multiple people can work simultaneously on features in separate branches without overwriting each other's work. Each commit contains who changed something and why, which is important for traceability and debugging. Git supports workflows with code reviews, CI/CD pipelines and rollback capabilities, so errors are quickly detected and fixed. Integration with tools like GitHub Actions and GitLab CI helps automate quality during every push. For example, see the GitHub Actions documentation for examples of CI workflows: https://docs.github.com/actions
Core concepts in one sentence
- Repository: the project folder containing the .git directory
- Commit: a snapshot of your code including metadata
- Branch: a reference to a set of commits
- Remote: an external repository (e.g. origin)
- Staging area (index): intermediate layer between working tree and commit
Useful git commands and what they do
Below you will find an elaborated list of commands that are most useful in practice. For each command, I explain what it does, when to use it and give an example.
git init
Initialises a new Git repository in the current folder. Use this if you want to start a project locally with version control.
Tip: Immediately add a .gitignore with files that should not be under version control (build-artifacts, credentials, node_modules).
git clone
Creates a local copy of a remote repository. Retrieves the full history.
git clone https://github.com/organisatie/project.git
Tip: Use -depth for a shallow clone if you only need the latest history.
git status
Shows which files have been modified, which are staged and which are unstaged. This is often the first command you run.
git add
Place changes in the staging area so that they become part of the next commit. You can add individual files or everything.
git add index.html
git add -A # all changes
Tip: Use small, logical commits by adding and committing related changes each time.
git commit
Create a snapshot of steady changes. Write clear commit messages.
git commit -m "fix: responsive header and accessibility improvements"
Tip: Use conventions such as Conventional Commits for consistent messages: https://www.conventionalcommits.org
git log
Shows the commit history. Useful flags: -oneline -graph -decorate -all for a compact view.
git log -oneline -graph -decorate -all
git diff
Compare changes between working tree, index and commits.
git diff # unstaged changes
git diff -staged # staged changes
git diff HEAD~1..HEAD
Tip: Use this to check what you are going to commit.
git show
Displays the content and metadata of a specific commit or ref.
git show 7f3a2b1
git branch
Shows or makes branches. -a also shows remotes.
git branch # list local
git branch -a # list including remote branches
git branch feature/search
git switch / git checkout
git switch is the more modern way to switch between branches (git checkout is also possible).
git switch feature/search function
git switch -c feature/new
git merge
Merge another branch into your current branch. You can get a fast-forward or a merge commit.
git switch main
git merge feature/search
Tip: Always check tests after a merge and resolve conflicts.
git rebase
Move your commits on a new base; this gives a linear history. Use rebase locally and before you push to remote to keep history clean.
git switch feature/search function
git rebase main
Note: rebase rewrites history - don't do this on shared branches without consultation.
Read more about merge vs rebase: https://www.atlassian.com/git/tutorials/merging-vs-rebasing
git fetch / git pull / git push
fetch retrieves refs without merging. pull is fetch + merge (or -rebase). push pushes your commits to remote.
git fetch origin
git pull -rebase origin main
git push origin feature/search
Tip: Use git pull -rebase if you want a neat history.
git stash
Save temporary, uncommitted changes and clean up your working tree. Useful if you need to change context quickly.
git stash
git stash list
git stash doll
git restore
Recover files from commit or delete them from the staging area. This is the more modern replacement for certain checkout operations.
git restore README.md # restores working tree
git restore -staged README.md # removes from staging
git reset
Move HEAD and possibly index/working tree. -soft, -mixed, -hard have different impact. Use with caution.
git reset -soft HEAD~1
git reset -hard HEAD~1 # destructive
git cherry-pick
Transfer a specific commit to your current branch. Useful for hotfixes.
git cherry-pick 3a4b5c6
git clean
Delete unversioned files. Note: irreversible without backup.
git clean -fd
git mv / git rm
Move or delete files while preserving history.
git mv oldName.php newName.php
git rm unwanted.txt
Best practices and workflows
- Make small, logical commits with clear messages. Describe the why, not just the what.
- Keep sensitive data never in the repo; use environment variables and secrets in your CI platform.
- Choose a branching strategy that suits your team: GitHub Flow is simple for continuous deploys; GitLab Flow helps with multiple environments. See workflows: https://www.atlassian.com/git/tutorials/comparing-workflows
- Use git rebase locally to keep your feature branch up-to-date, but use git revert on shared branches to safely roll back changes.
Concluding remarks and sources
With these commands and explanations, you'll have a solid foundation for working efficiently with Git. Git offers a lot of depth - from simple commits to advanced rebase and bisect workflows - but by understanding the core concepts and practising the above commands, you quickly become more productive.
Recommended reading tips and references:
- Official Git documentation: https://git-scm.com/docs
- Pro Git (free online book): https://git-scm.com/book/en/v2
- Merging vs rebase (Atlassian): https://www.atlassian.com/git/tutorials/merging-vs-rebasing
- GitHub Actions (CI/CD): https://docs.github.com/actions
- GitLab CI/CD: https://docs.gitlab.com/ee/ci/
👉 Funkhaus goes the extra mile for you
We are the all-in-one partner that takes care of everything: from creative web designs to technical optimisations and strategic content. You focus on your business, we take care of the rest.
Stuur een mailtje, of plan meteen een afspraak!
Krijg gratis en vrijblijvend persoonlijk advies
👋 Hi, we are there for you!
What our partners say
Expo Z
Always accessible, always helped quickly and professionally.
Very pleased with our fun and smooth collaboration!
Emmanuel Verraes
Very hands-on and service-minded! I have been recommended Funkhaus by another customer and I - on turn - highly recommend their services.
Angelique Lijffijt
I approached Wout as part of a website for an estate agent where Realworks needed to be built in and am very pleased with the result. Funkhous has a professional approach and fast service. Definitely highly recommended.
Chayenne Van Den Eynden
Very satisfied with the service , always in good order
Hans Peeters
Perfect guidance to the creation of our new school website!
Good cooperation, quick follow-up.
Yves Van Pelt
Our website was created by Funkhaus. Wonderful result and overall more than satisfied with the approach, listening to our wishes, fresh whole and above all a good working product. Thanks for everything Wout. We can only recommend you.
Niels Geenen
These guys definitely deserve 5 stars! good approach, good communication and beautiful design.
Definitely highly recommended!
Yv. Private
Always a very quick response and strong in communication. Wout can switch quickly and always understands immediately what I mean. The end result is therefore always quick and immediately satisfactory. Definitely highly recommended!
Ann Adriaensen
Our old website has been given a complete makeover. Online ordering was made possible with customisation, a clear layout was proposed with plenty of space for photos and texts. I am very proud of the end result. But also very satisfied with the service and way of working.
Laura Marie Belmans
Very nice company that always offers fast and quality service to its customer. In recent years, they have already brought several jobs to a successful conclusion. Very satisfied with customer focus, services rendered and smooth communication.