Don’t wait to clean your codebase, keep it clean from the start. Our team has had problems moving between branches and there are many reasons we have had issues. Right from the start, none of us cloned the main branch before making our own branches, so we have no matching commit history, therefore we have been unable to merge branches together.
Additionally, we did the one thing that should never be done, we ignored the .gitignore. Never do that! Our repository was filled with personal preferences and config files, log files, library files, and large packages that had been downloaded from the Unity asset store. This in combination with the fact that we started on distinct branches means that there were multiple copies of the files being uploaded and our free GitHub repository almost hit the size limit. This also meant whenever we tried to change branches, we needed to spend thirty minutes to and hour downloading everything from the branch. This has been a serious problem, and now is the time for it to stop.
So, this week has been a week of progress, but also a week of organization and cleaning the codebase. I have spent hours cleaning, merging, and configuring gitignore files.
Configuring .gitignore:
Configuring these files were easier than I expected. This page was very helpful in learning how via the examples provided: https://riptutorial.com/git/example/885/ignoring-files-and-directories-with-a–gitignore-file.
Cleaning:
Once the .gitignore files were configured, I was able to safely remove any of the files that were now being ignored by git. If people’s local repository needed the files, it would not remove them, but it also meant that we did not need to download them when switching branches.
Merging:
Since none of our branches shared a commit history, merging was a bit more tricky, but I developed a method that works pretty well. I simply created two Unity projects, one to be the one that in the main branch, and another that is temporary. With the temporary project, I could pull any branch that needed it’s code to be merged to the main branch, then could navigate to the local repository and simply copy and paste the files into the main project. This worked easily because none of us were working on the same files. I did need to rename one scene before copying it over because it shared a name with the scene from the main branch.
All in all, I probably spent about 6 hours this week trying to clean the codebase. We should have kept it clean from the beginning, but it has been a great learning experience. But please, don’t be like us. Keep your repository clean from the beginning, and above all, don’t ignore gitignore.