Search Unity

How does version control work?

Discussion in 'Editor & General Support' started by Marscaleb, Apr 10, 2021.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    I've heard some people talk about the importance of version control, but I've never really heard anyone explain what it is and how it works and how you use it.

    I mean, obviously by the name I can glean that it is a system to keep everybody's work together; to make sure that what one person does doesn't accidentally override what someone else has done, and to make sure someone else's work doesn't get lost.

    But how does that work? How is that even so necessary outside of very large companies? How would I go about implementing it within my Unity project, or would it even be worth doing so when I have but two computers working on my game?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    I'll use Git as an example here, but much of this applies to all version control software.

    Version controlling allows you to manage changes made to your project. It tracks what files have changed, what specific contents of each file were changed, when they were changed, who changed it, and provides ways to undo or redo changes up to a specified point in time.

    Beyond that, version controlling also allows you to "branch" your project. A branch is essentially a separate group of tracked changes. Any changes you make to branch A will not apply to branch B, for instance.
    When you initialize your project with Git, a default "main" branch is created, where your project is tracked automatically.

    Other branches are typically created when adding features, refactoring code, fixing bugs, or whatever else you feel necessary.
    This ensures that whatever changes you make are not "permanent", and if you end up catastrophically breaking things by accident, you can simply revert back to a branch before everything went caput.

    Whenever you feel a branch as fulfilled its purpose (I.E: a feature was implemented, bugs were fixed, etc.), you can then merge the branch into another branch (usually the "main" branch) to combine the changes of both branches.
    And once again, at any point in time can changes be undone or redone, so if you merge something by accident, that can be undone as well.

    When you're done making any changes, you typically want to publish (or "push") them to some form of remote storage (or "repositories"), which acts pretty much as a permanent up-to-date backup of your project and all of its versions.
    GitHub, GitLab, and BitBucket are some free & widely-used remote Git services meant for this.
    Once your project is "pushed" to a remote repository, you can "pull" it into any local PC and always be sure you have the correct/up-to-date version to edit on. No more need for multiple backup files with different names being passed around.

    Version controlling can benefit anyone working on any project, whether in a team or as an individual. It's a great way to keep things organized and ensure that you always have up-to-date backups or other versions of your projects, while being able to make/manage/undo changes without worrying about breaking things.

    People often say that once you start using version control software, you'll wonder how you ever worked without it, and I have to agree. Once I started using Git, I can't go back to not using it.

    Some more info:
    https://betterexplained.com/articles/a-visual-guide-to-version-control/
     
    luisquid likes this.
  3. luisquid

    luisquid

    Joined:
    Mar 21, 2015
    Posts:
    38
    Vryken likes this.
  4. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    Thank you; that was very helpful.

    I guess now I need to work out some practical application.
    I'm really just working alone, but I am interested in using some version control so I can work between two different computers. (And having a backup is always nice.)
    With that in mind, I'm not just looking to keep code together, but I'd need to be able to push and pull a whole game project. All my scenes, my project settings, my materials and meshes and prefabs...
    Even if I managed to have my chosen version control service not track certain larger files that are unlikely to change, I would still wind up using a fair chunk of space, especially if it would be retaining older versions for me.

    I can see how this could be helpful, but I am starting to suspect it might not be very economically viable for me. The cheaper Git plan only supports 2 Gigs of storage. Unity mentions two other companies that Unity specifically works with, but I'm having a hard time find what of their services is what I'm actually looking for.

    What would be a more viable solution for my situation?