Git

Merging Repositories in to a single repository

In order to merge repositories into a single repo with

  1. Each project in their own directory
  2. The whole history maintained for them
  3. No use of rebase and other dangerous/complicated features of git

Do the following:

  1. Pick the repo everything is being merged into (Repo A).
  2. Go to a repo you want to merge into Repo A (Repo B).
  3. [B] Pick the name of the subdirectory you’d like Repo B to be in when in Repo A and create that folder (e.g. mkdir repo_b )
  4. [B] Move everything into that folder using git: git mv !(repo_b) repo_b
  5. [B] Commit that in Repo B.
  6. [A] In Repo A add a remote to Repo B’s full folder path: git remote add repo_b /home/me/projects/project_b
  7. [A] Merge Repo B in to Repo A: git merge -S --allow-unrelated-histories repo_b/master
  8. [A] Remove the remote: git remote rm repo_b

Repeat starting at step 2 until all the repos are merged in to Repo A.

Sources: [1], [2]

Aliases

Super useful in git to take advantage of advanced features without typing so much each time.

Not the same thing as bash aliases, although some of these could be easily implemented as zsh/bash aliases or functions.

To add aliases go to your $HOME folder and edit or create .gitconfig. Update it like below with some example aliases I’ve picked up.

[alias]
    lol1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    lol = log --oneline --graph --color --all --decorate

For inspiration on aliases look at other’s dotfiles on github. I took a lot of inspriation from @jessfraz’s .gitconfig