Though Git is a revolutionary tool to enable version control and collaboration between developers, there are a lot of intricacies related to Git that go well beyond just adding, merging, and commiting. Getting a strong handle on Github allows you to more seamlessly build an application by yourself or with other collaborators.
One VERY important aspect to get a handle on very early in one’s career as a programmer is the
.gitignore file that is created once you initialize your application (using the command
git init). Essentially, the gitignore file is a document that keeps track of all of the files that you DON’T want to track with Git. For example, when you type the command
git add . into your terminal, you tell git to start tracking all of your files. Then when you commit these changes and push these changes up to a repository (e.g., Github), all of the files in your application get pushed to the repository.
However, there are some files that you do not want to push up to any sort of public repository. These are files that:
- Contain sensitive information about your application
- Contain temporary data or data that is only specific to your local environment (these tend to create a lot annoying of merge conflicts when you are collaborating with others)
So what are these files specifically? As the majority of my web development has been focused on Rails apps, here is a good model for a simple .gitignore file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
If you’re like me and you like sticking to your terminal when interacting with git, you can add files to your gitignore using the following method:
echo file_or_folder_name >> .gitignore
It is good practice to add all your gitignore files at the beginning of every Rails app so get in the habit of setting this up early. The template provided above is a very barebones gitignore file. As you develop your application, always try to think whether a file really needs to be tracked by git or whether it is better left untracked.