Git repository setup
Dec 18, 2016
2 minute read

If you’re setting up a git repository for a team there are a few crucial setup tasks that must be done to avoid a handful of common problems.

Create a .gitignore file

In the root of the git repository create a .gitignore file. This is used to exclude build artifacts from being added to the repository. Enter a list of file wildcards like this:

bin
obj
*.user

If you’re not sure what to exclude visit gitignore.io and plug in the IDEs and programming languages you expect to use. This is a bit of a shotgun approach; it’s better to make informed decisions about what to exclude yourself if possible.

Create a .gitattributes file

In the root of the git repository create a .gitattributes file. This is used to configure git’s behaviour. Importantly, it overrides settings configured by the user. This is important because in larger teams it’s very likely that some developers will have configured important settings (such as line-ending normalisation) in a way that clashes with other developers. These issues are prevented by .gitattributes. Inside .gitattributes either completely disable line-ending normalisation:

* -text

Or set it to normalise files that it believes are text files:

* text=auto

Opinions differ on the most appropriate way to handle line endings. The most important thing is that it’s consistent across all contributors, and configuring it in .gitattributes ensures this.

Configure team members’ username and e-mail

Notify all team members that they need to configure their git user name and e-mail. This ensures the metadata in commit messages are accurate. If using a hosted repository, like Github or BitBucket, ensure these values match each user’s account details.

Tell your team to run these commands:

git config --global user.name "Joe Bloggs"
git config --global user.email "joe.bloggs@localhost.com"

If team members don’t want to set these options globally they can navigate into their repository and run the commands without the --global flag.


Back to posts