git workflow - Replace all existing files in git repository with a different remote branch except the ones in .gitignore -
i have several repositories have merge 1 core
repository into. core
repository setup remote
repository in every repository.
generally, workflow update repositories goes this:
git reset --hard origin/master git pull origin master git fetch core master
i git merge --squash core/master
, fix conflicts before pushing repository remote
.
this fine, except little redundant because aside in .gitignore
file each repository, in these repositories should technically same core
repository.
as number of repositories expand, i'm wondering more efficient way of pulling core
branch these repositories given need replace existing files except ones mentioned in .gitignore
every 1 of them while maintaining integrity in git history , logs.
you can combination of git , bash. i've written sample script show how can done. can modify , make better. i've provided explanation also. file called adder.sh
.
#!/bin/bash # $1 -> files branch want (core) # $2 -> branch want merge (master) git checkout $2 git diff --name-status $1..$2 | grep '^\(d\|m\)\s*' | cut -f2 > ~/.dummy git checkout $1 -- $(cat ~/.dummy) git add .
to invoke it, use $ sh adder.sh core master
. after newly added , modified files core
branch added master
repo. git status can see what's new, commit , push accordingly.
$ git commit -m "skipping conflicts" $ git push
some explanation how works:
$ git diff --name-status master..core
produces following output:
m public/stylesheets/main.css # modified d public/templates/createuser.html # present in core branch , not master (new file) public/templates/dashboard.html # present in master , not in core branch (don't touch)
so write simple regex select modified , new files , modify proper format , store in temporary file.
$ cat ~/.dummy public/templates/createuser.html public/stylesheets/main.css
then need add files our current branch, use git checkout. see this answer how git checkout
.
there way this. official way, using git rerere
. the man page:
in workflow employing relatively long lived topic branches, developer needs resolve same conflicts on , on again until topic branches done (either merged "release" branch, or sent out , accepted upstream).
this command assists developer in process recording conflicted automerge results , corresponding hand resolve results on initial manual merge, , applying recorded hand resolutions corresponding automerge results.
note: need set configuration variable rerere.enabled in order enable command.
this article gives decent overview of command , use case.
Comments
Post a Comment