Skip to content

Instantly share code, notes, and snippets.

@sunsided
Last active October 12, 2019 19:19
Show Gist options
  • Save sunsided/506105bee18a92801c7665ca1a9fcfa0 to your computer and use it in GitHub Desktop.
Save sunsided/506105bee18a92801c7665ca1a9fcfa0 to your computer and use it in GitHub Desktop.
Git for Unity repository bootstrapping including .gitignore, .gitattributes, and Git-LFS.
#!/usr/bin/env bash
set -eo pipefail
echo "Creating Git repository ..."
git init
echo "Applying private user configuration ..."
git config user.name "<YOUR NAME>"
git config user.email "<YOUR EMAIL ADDRESS>"
git config user.signingKey "<YOUR GPG SIGNING KEY>"
# Configuring Unity YAML merge
# - https://docs.unity3d.com/Manual/SmartMerge.html
# - https://gist.github.com/sunsided/506105bee18a92801c7665ca1a9fcfa0 (unity-merge script)
# - https://gist.github.com/sunsided/366d7b6e4e8c3df14fea9b9c3f628d6f
echo "Configuring YAML merge"
git config mergetool.unityyamlmerge.trustExitCode false
git config mergetool.unityyamlmerge.cmd 'unity-merge merge -p "$BASE" "REMOTE" "$LOCAL" "$MERGED"'
echo "Creating standard files ..."
if [ ! -f "README.md" ]; then
echo "# Unity Project" >> README.md
fi
wget --quiet -o .gitignore -c "https://gist.githubusercontent.com/sunsided/366d7b6e4e8c3df14fea9b9c3f628d6f/raw/2c7616106d102595aae673e02a944bb1fdbee778/.gitignore"
wget --quiet -o .gitattributes -c "https://gist.githubusercontent.com/sunsided/366d7b6e4e8c3df14fea9b9c3f628d6f/raw/2c7616106d102595aae673e02a944bb1fdbee778/.gitattributes"
echo "Enabling Git-LFS ..."
git lfs install
echo "Adding standard files ..."
git add .gitignore .gitattributes ./README.md
echo "Setup done."
#!/usr/bin/env bash
UNITY_BASE_PATH="$HOME/Unity"
MERGE=$(find $UNITY_BASE_PATH -type f -name UnityYAMLMerge | sort -r | head -n1)
$MERGE "$@"
@sunsided
Copy link
Author

sunsided commented Oct 12, 2019

To make it work, download the git-init-personal-unity.sh script e.g. to ~/.local/bin/git-init-personal-unity, adjust the user configuration values and make it executable. Also, download the unity-merge file to the similar directory, e.g. ~/.local/bin/unity-merge.

When run from a new Unity project directory, it will:

  • Initialize a Git repo and sets your user configuration local to this repository,
  • Create a .gitignore file suitable to suppress all unneeded files on Linux, when using JetBrains Rider, and for Unity in general,
  • Create a .gitattributes file for use with Git-LFS,
  • Installs Git-LFS :)
  • Creates a default README.md file.

Having local user configuration isn't always needed, but comes in handy when you do work with different credentials on different machines. See this Gist for the .gitignore and .gitattributes files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment