A good day is a productive day or at least a day wherein you've solved a problem that bothers you and will probably continue to bother you for a long time. I am not a perfectionist but I am bothered by the smallest inefficiencies partly because for the past year and 8 months, I worked for a company values optimization and automation. If a bot can do it for you, let it. Automate everything you should!

Last year, I worked in different islands and was still able to deploy regardless of the fact that the Philippines has the worst internet service providers in the world. All I had to do was click on a button or type a few words on chat. We owe these improvements to our former CTO, Michael Chletsos, the former VP of EngineeringTitas and of course the Operations team. If you are curious about this, you can view Assembla's blog.

Introducing Git Projects

Git Projects is one of the CLI tools I created to help me with my work everyday. There is nothing magical about it but I had to create it anyway. I just woke up one day with a long list of things to do for both work and my own ventures and saw how disorganized my git projects look like. It was a mess. I had to keep checking on my remotes and do the same damned things for every Mac I use.

I owe the idea to Bundler. If Bundler has a Gemfile, Git Projects has git-projects.yml file for storing all project details needed for cloning and fetching changes from different remotes.

What It Does Exactly

It allows you to easily keep track of all of your projects in a single config file, group these projects so you can fetch changes by group and makes it easy to add remotes including an "all" remote meant for developers who want to push changes for all remote repositories.

Git for Distributed Environments

Git is designed for distributed environments. This means that with a proper workflow, it should be easy to contribute to a project that involves a lot of people. People who might render this senseless do not use branching or probably do not use git fetch often.

Creating the Config File

The config file can be called anything as long as it's a YAML file. It can reside anywhere on your computer. If you want to use Dropbox to store that file, you can.

project1:
  origin: path/to/repo
  github: path/to/repo
  assembla: path/to/repo
  heroku: path/to/repo
  root_dir: path/to/root_dir #where your repository will be cloned
  group: name # useful if you do not want to fetch changes for all
project2:
  origin: path/to/repo
  github: path/to/repo
  assembla: path/to/repo
  heroku: path/to/repo
  root_dir: path/to/root_dir #where your repository will be cloned
  group: web

Installing the Gem

I've tested on Ruby 2.1.0 and it works.

gem install git-projects

Adding the GIT_PROJECTS Environment Variable

Simply update your .bashrc or zsh config file. My setup is a little more complicated so it's in a different file.

export GIT_PROJECTS=$(/path/to/git-projects.yml)

It's important that this command works:

echo $GIT_PROJECTS

Initialize the Git Projects

Whether the projects have been cloned or have yet to be initialized, this command should work with a valid config file:

git-projects init

That command does a lot of things and one of these involves adding remotes including the "all" remote.

The "All" Remote

If you have a small project that has a remote repository and is hosted on Heroku. You might find yourself fixing a typo and trying to push on remotes when you can just do it with one command:

git push all --all

Fetching Changes

Fetching changes for all repositories would seem to be insane in most cases so I recommend grouping and using this command:

git-projects fetch tea

That fetches changes for all of the projects with a group called "tea." Note that it will check for all remotes for all projects under that group.

Git Alias for Pulling Changes

For most people a gem could be too much if all projects reside in one directory. And for some people, they like to use pull to automatically merge changes from the remote repository to what they have locally. Of course that's very sane and you won't need Git Projects gem at all.

You can simply use this shell script and create an alias to run that script.

comments powered byDisqus

Hello! I am Kat. I've been a developer for several years. When I'm not sitting down, reading and working for long hours, I am traveling to some place of interest.
If you want to reach out, you can send me an email or add me up on Google Plus.