restore: Implemented with stash. (Does not work for adding untracked files.)
[gitgitconfig.git] / gitgitconfig-init
blob1ddc18d32b84c4599c4124bf2209cdc256c68bd0
1 #!/bin/bash -ex
3 if ! [[ "$DATADIR" ]]; then
4 DATADIR=/usr/share/gitgitconfig
5 fi
6 readonly DATADIR
8 # We don't want (for now) to work with .git in nonstandard locations.
9 #readonly REPOCONFIGDIR="$(git rev-parse --git-dir)"
10 readonly REPODIR="$(git rev-parse --show-toplevel)"
12 cd "$REPODIR"/.git
14 git init
16 # Local FS optimizations (like "git clone --reference")
17 # (http://git-blame.blogspot.fr/2012/08/bringing-bit-more-sanity-to-alternates.html):
18 echo ../../objects > .git/objects/info/alternates
19 # Perhaps, you can skip this if you are following this sequence of commands manually.
21 git remote add -f -m GITCONFIG/master origin "$REPODIR"
22 # In order to restore your saved .git/config,
23 # we'd like to pull from some <remote>/GITCONFIG/master in origin
25 # And when saving your .git/config,
26 # we'd like to push our local master to GITCONFIG/master in origin
27 # (for further propagation to remote servers).
29 git config branch.master.remote origin
30 git config branch.master.merge GITCONFIG/master
31 git config push.default upstream
33 # We'll see whether this will work out.
35 ##############################
36 # What to track.
38 # There are 2 variants:
39 # to put the patterns under version control
40 # (so that anyone who gets the branch with this stuff can comfortably
41 # use it with plain git, without my scripts):
42 cp -v "$DATADIR"/gitignore .gitignore
44 # or:
45 # to put the patterns not under version control
46 # (so that there is no extra junk in the branch, but then
47 # it's comfortable only if everyone uses this script for init):
48 #cp -v "$DATADIR"/gitignore .git/info/exclude
50 # Don't forget to "git add .gitignore" afterwards...
52 # Let us create the initial commit,
53 # operating without a HEAD is inconvenient in Git.
54 git add .gitignore
55 git commit -m 'Initialized for saving config; track only relevant .git/ files.'