Merging Git Repos for Archival Purposes

TL;DR I had reason to want to combine git repos into one big repo consisting of repos in their own folders, while ideally maintaining the histories of all those repos for archaeological purposes. There are many reasons why someone would want to do this, and my specific use case isn’t relevant. Good luck. Why so complicated? ‘Hidden’ files (dotfiles) suck Shell Wildcards suck Wildcards with selective exclusions (i.e. .git) suck File names with spaces suck Trailing Slashes suck Rewriting History sucks Raw version because I don’t trust GIST and embeds and such…. #!/bin/bash usage() { cat << EOF This script imports a git repo (accessible from https://\$origin/\$user/\$repo) and all its history as subdirectory of a destination (available locally at \$dest) It is designed for non-production, archival processes and may destroy everything you've ever loved because you looked at it funny. You have been warned. The structure of the destination will end up something like this: ~/src - \$dest - origins - \$origin - \$user - \$repo Required Arguments: -u|--user: The user that owns the repo to be imported -r|--repo: The name of the repository to be imported -d|--dest: The local name of the destination repository (assumed to be under ~/src) -o|--origin: The git server that is the origin of the repo to be imported EOF } if [ $# -le 6 ]; then usage exit 1 fi while [[ "$#" -gt 0 ]]; do case $1 in -u|--user) user="$2"; shift ;; -r|--repo) repo="$2"; shift ;; -d|--dest) dest="$2"; shift ;; -o|--origin) origin="$2"; shift ;; *) echo "Unknown parameter passed: $1"; usage; exit 1 ;; esac shift done tmp="/tmp/_${dest}_tmp" echo "Importing $origin/$user/$repo into $dest" rm -rf ~/src/$repo cd ~/src git clone https://$origin/$user/$repo cd $repo git filter-branch \ --tree-filter "mkdir -p $tmp/origin; git ls-files | cpio -pdumB $tmp/origin; git ls-files | xargs -d '\n' rm -r; find . -type d -empty -delete; mkdir -p origins/$origin/$user; mv $tmp/origin origins/$origin/$user/$repo/"\ --tag-name-filter cat --prune-empty -- --all if [ $? -eq 0 ]; then ## WAIT PATIENTLY cd ../$dest git remote add $repo ../$repo git fetch $repo --tags git merge --allow-unrelated-histories $repo/master #Youre on your own if you want a different / multiple branch(es)... git remote remove $repo else echo failed for $user/$repo fi

June 23, 2020 · Andrew Bolster

Guide to Persistent Reverse SSH Shells and Port Forwards

Idiot proof setup for persistent reverse shells / port forwards (same thing) under a Ubuntu VM remote and my Dreamhost server, but should apply to nearly* all *nix’s First off, some terms to keep this easy. I want to be able to access my in-office VM, xavier from my server magneto (not my names, but they conveniently complement). xavier is not publicly accessible, but magneto is. I’ll be replacing all of the FQN’s with these terms so expand on your own. In generic terms, xavier is the remote machine (i.e the one behind some NAT firewall or such that you want to get access to) and magneto is the local machine. Its a bit confusing since all of the work is done on xavier, but it makes sense in the long run. Just trust me and get on with it. ...

December 8, 2011 · Andrew Bolster

Customised User Directories in Ubuntu

I’ve been doing alot of messing around in Ubuntu recently and there are lots of tweaks I like to make. One of them being to show the contents of my home folder as my desktop; I don’t need any more pointless folders…. Dead easy, there is a .config directory under your $HOME dir, containing several files. The one we need is user-dirs.dirs , and it looks something like this. # This file is written by xdg-user-dirs-update # If you want to change or add directories, just edit the line you're # interested in. All local changes will be retained on the next run # Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped # homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an # absolute path. No other format is supported. # XDG_DESKTOP_DIR="$HOME/Desktop" XDG_DOWNLOAD_DIR="$HOME/Downloads" XDG_TEMPLATES_DIR="$HOME/Templates" XDG_PUBLICSHARE_DIR="$HOME/Public" XDG_DOCUMENTS_DIR="$HOME/Documents" XDG_MUSIC_DIR="$HOME/Music" XDG_PICTURES_DIR="$HOME/Pictures" XDG_VIDEOS_DIR="$HOME/Videos" And this is what I changed mine to ...

June 1, 2010 · Andrew Bolster

Automagic Kernel Cleaning under Ubuntu

Sick of having dozens of old kernels sitting under your /boot/ dir? Want a simpler boot-life? Well we’ve got the solution for you. Just one course of cleankernel once an upgrade cycle will remove all previous kernel entries from your bootloader and /boot/ dir. Basically, it lists what kernels you currently have in your /boot/ and removes them using apt .

May 31, 2010 · Andrew Bolster

Listing just dot-files

Its a problem that I’ve come across, and I’m not the only one, so heres what works for me to find those pesky files that start with a . ls -a | egrep -i "^\." This only works in the current working directory, which is the normal usage. FYI the reason that this is problematic is that the ‘.’ symbol is a single character wildcard; most people are familiar with the asterisk ‘*’ indicating ‘anything, however long’, whereas the ‘.’ means ‘any single character’. ...

April 9, 2010 · Andrew Bolster

Chmod on lots of files

My lil-NAS has plenty of space but is maddeningly underpowered. I came across a permissions issue where, depending on how the files in question got there, they would not be accessible to my windows boxes because they were owned by root (I have no doubt that its my fault!) So, first attempt was nice and easy. $chown -R smbusr:smbusr * But this was taking a horrific amount of time, so I thought “There must be a better way”. ...

March 23, 2010 · Andrew Bolster

Line Parsing Reminder (Duplicate removal)

So, say you have a long list of instruction (like multiple apt-get install lines) and you want to eliminate common words? Easiest way to do it is (assuming you have all of the instrustions in “list.txt”) [FYI the ‘' character indicates a continuation of a single line ] cat list.txt\ | tr ’ ’ ‘\n’ \ #Expands all space characters to new lines | sort | uniq \ #sorts each line, and then eliminates duplicates ...

March 12, 2010 · Andrew Bolster

Shared Items - 24/02/2010

Nice process, but what about the engineering bits? Wish I had this article in my QUB Software Engineering module Pattern matching with Bash (not grep) Brilliant article on Bash’s built in pattern matching. The next generation of ad serving for online publishers RFID tracking system Researchers Say Women Secretly Desire Hairy Geeks As my partner Beth says; “I’m ahead of the curve”

February 24, 2010 · Andrew Bolster

Change Of Plans.....

My attention span isnt really that great with projects, so the thought of doing the entire Project Euler in several different languages was never realistically getting off the ground. (FYI Problems All On One Page ) So, modification and extension to the previous idea; Take one random number generator (java.util.random) and a list of languages I think I should have at least a cursory knowledge of. Each time I finish one problem, push a button and it tells me what language to use for the next one. ...

June 28, 2009 · Andrew Bolster

MBWE Fuel Gauge -> Speedometer conversion

The Fuel gauge on the front of my MBWE is fairly useless, noone cares, so why not repurpose it as a speedometer? first, stop it displaying the “fuel” Stolen from http://kyyhkynen.net/stuff/mybook/reduce_disk_usage.php Disable the service that displays the disk usage with the leds in the front panel of your MBWE. Admit it, the feature is pretty much useless and because the service has to check the amount of free space on the disk(s), it is causing disk access. ...

November 6, 2008 · Andrew Bolster