Git for developers - version control from basic to advanced

In today’s world of software engineering, working without a version control system is practically impossible. Whether you’re building a simple personal website or a complex enterprise-class system, you need to know, how git version control works. It is not just a tool for „backing up” code, but above all a cornerstone of teamwork, enabling features to be developed in parallel without the risk of overwriting the work of colleagues sitting next door.

The Basics: What is Git and how do you get started?

Git is a distributed version control system created by Linus Torvalds. The word „distributed” is key here – it means that every developer has the full history of the project on their hard drive, not just the latest version. This allows us to perform most operations locally, ensuring incredible speed.

The basic workflow in Git:

  1. Working directory: This is where you edit your files.
  2. Staging Area (Index): The place where you prepare changes for approval. You use the following command to do this git add.
  3. Local Repository: Once completed git commit, your changes are permanently saved in the local database with a unique identifier (hash).

If you want to store your code in the cloud and collaborate with others, you need to choose the right hosting provider. Check out our comparison: GitHub vs GitLab – a comparison of the platforms.

Branch management: Merge or Rebase?

Branches are one of Git’s most powerful features. They allow you to isolate work on new functionality (so-called. feature branch) from the main line of code (main). The real challenge, however, begins when we want to combine these changes.

Git Merge vs Git Rebase – which should you choose?

  • Git Merge: It creates a new „merge commit”. It preserves the full, chronological history of events, showing exactly when branches diverged and merged. It is safer for public branches.
  • Git Rebase: It rewrites the project history by merging your changes onto the tip of another branch. The result is a clean, linear history without unnecessary merge commits. However, caution is required – never rebase branches that other developers are working on!

You can find detailed technical information in Official Git documentation.

Advanced techniques: From Stash to Bisect

Once you’ve mastered the basics, it’s worth learning the commands that can save lives in critical situations. Knowing this, how git version control works at an expert level, it allows for the instant correction of errors in the history.

  • Git Stash: Imagine you’re working on a new module, but you need to fix a critical bug in the production environment straight away. git stash allows you to temporarily „set aside” unfinished changes without committing them, and then restore them once the error has been fixed using git stash pop.
  • Interactive Rebase (git rebase -i): It allows you to edit, squash or delete old commits. It’s the perfect tool for tidying up your commit history before submitting code for review.
  • Git Cherry-pick: This allows you to select a specific commit from any branch and apply it to the current branch.
  • Git Bisect: Pure magic when debugging. If you know the app used to work but doesn’t anymore, git bisect will guide you through the history using binary search, helping you find the specific commit that introduced the bug.

Work standards: GitFlow and trunk-based development

Simply knowing the commands isn’t enough – the team needs to be able to communicate with each other through code. That’s what workflows are for.

  1. GitFlow: A very rigorous multi-branch model (develop, Master's degree, hotfix, release). Ideal for large projects with regular releases.
  2. GitHub Flow: A simplified model based on short feature branches and pull requests. Ideal for teams using continuous deployment.
  3. Trunk-Based Development: Developers push small changes directly to the main branch several times a day. This requires a high level of technical expertise and sophisticated automated testing.

To make the most of these models, it’s worth combining them with automation. Find out more: CI/CD with GitHub Actions – deployment automation.

Common mistakes and how to avoid them (FAQ)

1. „I’ve committed the API keys to a public repository!” This is a critical error. Use tools such as git-filter-repo or BFG Repo-Cleaner to permanently remove the file from the entire history. Remember: simply deleting the file in a new commit isn’t enough!

2. Merge conflicts A conflict occurs when two people have modified the same line in the same file. Don’t panic. Git will highlight the problematic sections of the code. Your task is to choose the correct version, add the file to the staging area, and commit the changes.

3. Commits that are too large The rule is simple: one commit = one logical change. Commits such as „Bugs fixed and 5 new features added” are a nightmare when it comes to analysing the code later on.

Professional version control for your business

Understanding this, how git version control works, is the cornerstone of professionalism in the IT industry. It enables the creation of robust processes, the rapid reversal of incorrect changes, and seamless collaboration between multiple people on a single product. Remember that Git is not just a tool; it is a way of thinking about code as a living, evolving organism.

At 4ADStudio, we help implement advanced code workflows and automate deployment processes. We use GitHub – a code hosting platform, …in order to provide our clients with the highest quality software.

Is your project history a mess that nobody can make sense of? Get in touch! We’ll help you organise your repositories and implement standards that will speed up your team’s work.

Leave a Comment

Your email address will not be published. Required fields are marked *

Write to us

You want to improve
your business?

Bartłomiej Biedrończyk


    CALL ME
    +
    Call me!
    4AD
    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.