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/
π Heb je een leuk software idee?
Blijf er niet mee rondlopen! Vertel ons wat je zoekt.
Wij vertellen je direct wat het kost, hoe lang het duurt en hoe we het aanpakken. Duidelijk en zonder kleine lettertjes.
π Vrijblijvende even kennismaken?
Send an email, or schedule an appointment right away!
What our partners say
Charlotte Lambrecht - Charlie's Fit Studio
Would you like to have a top website/logo developed?
Then you've come to the right place at Funkhaus!
What I myself find hugely important in a collaboration is good communication. Wout was always very quick in answering my questions and looking for solutions. Everything was always discussed in consultation and there was room for brainstorming and creativity. If something didn't feel 100% right, Wout provided several alternatives until the feeling was completely right. It was also an absolute bonus to receive such positive support as a start-up.
A very nice collaboration resulting in a top website. Go check it out at www.charliesfitstudio.be
Leen Vermeiren
After being introduced to several website builders, we confidently went with Funkhaus to build our new website and choose our new corporate identity. Wout guided us through the whole process in a professional, efficient and friendly manner. We are very happy with this cooperation and can definitely recommend Funkhaus. Feel free to take a look at the website of Stella Matutina Wuustwezel.
Sander van Schoonhoven
Professional company. Contracted for website renewal. Sprint type approach. Are willing to adapt the project execution pace to the customer's available resources.
’t Anderhoes
Zeer goede en betrouwbare firma. Heeft noodzakelijke aanpassingen van websites goed en snel uitgevoerd.
Fanny Verstappen
I am very satisfied with working with this agency. They put my company pages on social media back in perfect order. They were always ready to help, thoughtful and also very friendly. Definitely highly recommended!
Jens Jansen
Zeer professioneel en een vlotte samenwerking
Tibor R. B. Bassez
We have been satisfied customers of Wout and his team for many years. Besides updating our website every week, he also keeps his finger on the pulse for the latest developments in ICT land.
Koen Van den Abeele
Top service!
Highly recommended to anyone looking for reliable & honest marketing support with a creative touch!π
Expo Z
Always accessible, always helped quickly and professionally.
Very pleased with our fun and smooth collaboration!
Nick Van der Hallen
Fantastic and honest company with very flexible and fast customer service. Funkhaus took our new website to the next level, with plenty of options to expand on later. Great to work with and highly recommended!