How do I setup Git for an UE4 project?

Hi!

My question is simple: how can I setup my git repository for an UE4 project? Or, in other words, which files/folders can I safely include in the gitignore file? Are there some tips to make this works flawless? :slight_smile:

Thank you in advance!

1 Like

You can commit any of your non binary files safely. The primary issue you will run into is binary files - such as assets, which is a problem for any binary file in VCS that does not have context for the files. By and large the issue exists for all common VCSs but with distributed ones like Mercurial and Git this is a compounded issue.

You should ignore the files created for MSVS, as they are likely to be created on any contributors machine when they run the batch script to generate them. This includes the sdf, opensdf, suo, DotSettings files.

You should also ignore the Saves directory as it wont be of much use to your buddies.

You will also want to ignore the Intermediate directory, as everything in there is generated or copied.

Whoever downvoted this questions should provide some justification in the comments to help the community understand what questions are good and what are bad. I believe the current position is that there are no bad questions.

As a general rule, you should check in all files that are required to make a successful build of your project and cannot be generated from other files. If you or someone else clones your project, they must have everything that is needed for the project - not more not less. Files that are not needed for your project or that can be automatically generated from other files in your project should not be included, because that would be a waste of disk space and just cause conflicts when someone downloads your latest version into their local workspace. The only exception may be documentation, readme files and sample code that may help someone with your project.

Here is a typical folder structure for a code-based project. The files and folders in bold should be included, the rest can (and should) be safely ignored:

  • Binaries*
  • Build - any custom build scripts or other build related dependencies you may have
  • Config - the default configuration files for your packaged project
  • Content - maps, content files and assets**
  • DerivedDataCache - temporary data files generated when you run the game
  • Intermediate - temporary files generated when you compile your code
  • Saved - local log & configuration files, screenshots, auto-saves etc. that are generated each time you run the game or Editor
  • Source - the source code of your project

*) If your project uses third-party libraries, i.e. when integrating some software components or hardware devices, you may have DLLs, LIBs or other files in your Binaries directory that must be included if your project depends on them. However, do not include the DLLs and debug files (.pdb) that are generated for the project itself, i.e. MyProject.dll and MyProject.pdb.

**) Make sure you do not discard your raw assets after importing them into the Engine. While they are not strictly required for building the project (the content packages should contain everything needed to run your game), we recommend that you keep them somewhere in version control. If you don’t want to keep them in your project’s repository (i.e. because you don’t want to give them to the public) you should at least maintain some other private repository for yourself so that you do not loose any changes and can always go back to prior versions of textures, static meshes, sounds and so on, if needed.

3 Likes

I’ve attached my .gitignore file for people to use as they need here. It ignores all the folders as mentioned above. To use it, copy the file into your root repository directory. Open a new command prompt (File->Open Command Prompt) and type “ren gitignore.txt .gitignore” without the quotations to rename the file.

Please note that .vcxproj files are being added into /Intermediate/ProjectFiles and they certainly don’t want to be ignored. However, I could not find a way of whitelisting it successfully within .gitignore so the file has to be explicitly added using git add -f ... :@

There’s no reason to put the .vcxproj files under source control because they are generated from the contents of the Source directory. Any changes to the project files made by the user will be lost anyway the next time the project files are regenerated.

Yes, you are right. You can just do File > Refresh Visual Studio Project to regenerate the project file. Thanks.

On Windows you can simply right-click on the .uproject file and select Generate Visual Studio project files from the context menu. I presume something similar is available on the Mac. You can also regenerate the project files for the currently open project in UnrealEd via File->Refresh Visual Studio Project.

What about the Content of the Build directory? Can I safely ignore it? Or at least the Build/Receipts subdirectory?

I’ve noticed, that since 4.9 there’s no icon anymore created to the Build directory. So can I safely ignore the Build directory since 4.9?

This is my current .gitignore file:

# UE4 Project directories to ignore
/Binaries/
/DerivedDataCache/
/Intermediate/
/Saved/
/Build/

# Visual Studio solutions
/*.sln
/*.sdf
/*.opensdf
/*.suo

# Linux Project files
/*.pro
/*.kdev4
/CMakeLists.txt
/Makefile

# Xcode Project files
/*.xcodeproj

Another option for creating a .gitignore file is to rename it “.gitignore.” The final . will be dropped, and it will not have an extension.