How to read your way to becoming a better developer

I have been writing software for a long time, and I’ve had the opportunity to learn about programming in many different settings. I have struggled through problems on my own, worked with teams, and…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to use Git to downstream changes from a template

Last week I had to update the version of Gradle Enterprise in a template and downstream the changes to all its implemented projects. I was fascinated how useful this is, especially if you have many projects that build on the same base. I only had to update the template and downstream the changes but in this article I will also describe how to create one of these templates and how to use it in a project.

A template has the purpose of sharing boilerplate code across the whole codebase, which reduces the time needed to start a new project and gives you more time to focus on the important stuff. More information here.

First of all, we need to create a new git repository on our favourite platform like GitHub, Bitbucket or GitLab. We can now clone the empty repository to our local machine and add the files we want in our template.

Then we just push the changes to the remote again.

Congratulations, you just created your first template

After creating the template, we can create a new repo for our project. After this is done, clone the template repo but with a different name than the standard repo name.

Git will still create the remote origin configurations with the up- and downstream URLs pointing to the template.

Since we want to push to our own project instead of the template itself, we need to rename the origin.

This way, the default location to push and fetch changes from is the project repository. At the moment, we would be able to still push changes to the template with:

If we now use the git remote -v command, we will see something like this:

If we now try to push something to the upstream, we get an exception that tells us that this repository does not exist.

First of all, we have to fetch the newest changes of the remote with:

Next, we can merge the changes, resolve conflicts if there are some and push to the project.

Now you have successfully downstreamed the changes of the template to your own project. Congratulations 👍 😸

This has not directly todo with the downstreaming itself but in the future I would research a little more about the dependencies to versions of other projects. The project I was upgrading had some dependencies to a specific version of another project. I didn’t know that and was wondering about the errors the whole time until I asked someone of my team for help.

Add a comment

Related posts:

How to Avoid Unnecessary Conflicts All Together

Conflicts are part of our life. Nevertheless, we all want to avoid them at all costs, right? There is no real need to get into conflicts or have them in our daily life. There is so much more harmony…