Levent Alpsal
Levent Alpsal

Reputation: 13

How to update Unity on all branches of a project

I'm working on a Unity project. We are using Git and have multiple branches. What is the best method to update project to a new Unity version on all branches with minimum hassle?

Note: I don't want to merge all branches and I don't want to update each branch separately.

Upvotes: 1

Views: 1587

Answers (3)

Marina Liu
Marina Liu

Reputation: 38136

There is no such git command which can update all branches at the same time.

Instead, you can achieve it by the workaround to update each branch by script.

Assume the project changed on master branch, you can update other branches as below:

  • To update all the files from master branch to other branches:

    git checkout branchname
    git checkout master -- .
    git commit -m 'update all the files same as master branch'
    
  • To update certain fles (such as test.cs) from master branch to other branches:

    git checkout branchname
    git checkout master -- test.cs
    git commit -m 'update test.cd from master branch'
    

Upvotes: 0

sonnyb
sonnyb

Reputation: 3524

Here are the steps to update Unity on all branches:

  • On your main working branch, update your Unity version. (I will assume your main working branch is master in this post, but dev is also a common convention.)
  • Commit all files that automatically change with the update.
  • Fix any immediate build errors that prevent the project from running.
  • Test your project to see if there are any regression bugs introduced by the update, and fix them. Commit any necessary fixes. (I recommend making your commits atomic so you can easily review what you had to fix manually during the update process.)
  • On all your other branches, git rebase on to master branch. (You can also git merge with master instead of rebasing, if you don't want to push new rebased branches. It also depends on the project's context. For more information on this, see posts such as "Merging vs Rebasing")
  • On all your other branches, check for build errors. In particular, because you're not updating each branch separately, you'll need to update anything that would have been handled by the Unity Automatic Obsolete API Updater
  • Recommended: only once you've confirmed that all Unity branches work locally, push all your branches so the update is available in all remote branches. You want to be able to revert your actions locally in case you discover an issue with updating one of your branches. If you run into an issue, you can git reset --hard to the original commit.

Also, here are some items that will make the update easier:

  • The project is not using a Unity version that's too far out of date. For example, if you're a few major versions behind, you'll likely have more obsolete API updates to deal with.
  • The branches are not too long-running. If the branches have deviated significantly away from master, you'll have more obsolete API updates to perform on each branch, and there's a greater risk of merge conflicts and hassles. (But you can verify whether this is an issue before you push the Unity update to remote branches.)
  • Your project is set up to use visible meta files
  • Unity Cache Server is set up so it will be quicker to load the project while you switch between branches with different Unity versions during the update process.

As a note, I think it's correct practice to not to update each Unity branch separately. However, I would recommend merging all branches into master if possible or at least making sure there aren't any long-running branches, as it could complicate the update process.

Upvotes: 0

anothernode
anothernode

Reputation: 5397

Update it in the master branch, then rebase all the other branches onto the tip of the master branch.

As a side note: usually it's not good practice to put external libraries into the version control of your own projects. They should get pulled in at build time.

Upvotes: 1

Related Questions