I have several repositories that I always have to merge one core
repository into. The core
repository is setup as a remote
repository in every repository.
Generally, my workflow to update repositories goes like this:
git reset --hard origin/master
git pull origin master
git fetch core master
I then do a git merge --squash core/master
and fix any conflicts before pushing the repository back to remote
.
This is fine, except it is a little redundant because aside from everything in the .gitignore
file for each repository, everything in these repositories should technically be the same as the core
repository.
As the number of repositories expand, I'm wondering what a more efficient way of pulling the core
branch into these repositories would be given that I need to replace all existing files except the ones specifically mentioned in .gitignore
for every one of them while maintaining integrity in git history and logs.
You can do it with a combination of git and bash. I've written a sample script to show how it can be done. You can always modify it and make it better. I've provided some explanation also. This file is called
adder.sh
.To invoke it, just use
$ sh adder.sh core master
. After this all newly added and modified files from thecore
branch will be added to themaster
repo. With a git status you can see what's new, then commit and push accordingly.Some explanation to how it works:
Produces the following output:
So write a simple regex to select only the modified and new files and modify it to a proper format and then store it in a temporary file.
Then we need to add those files to our current branch, so we use git checkout. See this answer for how to do so with
git checkout
.There is another way to do this. The official way, using
git rerere
. From the man page:This article gives a decent overview of the command and its use case.