├── pomysl.txt ├── pomysl2.txt ├── git-days ├── git-snapshot2 ├── git-clone-with-branches ├── git-list-all-objects ├── git-list-objects ├── git-stat ├── LICENSE ├── install.sh ├── alias.txt └── git-swapid /pomysl.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gajdaw-git-recipes/aliases/HEAD/pomysl.txt -------------------------------------------------------------------------------- /pomysl2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gajdaw-git-recipes/aliases/HEAD/pomysl2.txt -------------------------------------------------------------------------------- /git-days: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git log --pretty=format:%cd --date=short | uniq 4 | 5 | 6 | -------------------------------------------------------------------------------- /git-snapshot2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | COMMENT=wip 4 | 5 | if [ "$*" ]; then 6 | COMMENT="$*" 7 | fi; 8 | 9 | 10 | git add -A 11 | git commit -m "$COMMENT" 12 | -------------------------------------------------------------------------------- /git-clone-with-branches: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cloneWithBranches() { 4 | git clone $1 $2; 5 | cd $2; 6 | git checkout-remote-branches; 7 | git remote rm origin 8 | }; 9 | 10 | cloneWithBranches 11 | -------------------------------------------------------------------------------- /git-list-all-objects: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | cd "$(git rev-parse --git-dir)" 6 | 7 | # Find all the objects that are in packs: 8 | 9 | find objects/pack -name 'pack-*.idx' | while read p ; do 10 | git show-index < $p | cut -f 2 -d ' ' 11 | done 12 | 13 | # And now find all loose objects: 14 | 15 | find objects/ \ 16 | | egrep '/[0-9a-f]{38}' \ 17 | | perl -pe 's:^.*([0-9a-f][0-9a-f])/([0-9a-f]{38}):\1\2:' \ 18 | ; -------------------------------------------------------------------------------- /git-list-objects: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | OBJECTS=`git list-all-objects` 4 | 5 | for sha1 in $OBJECTS; do 6 | TYP=`git cat-file -t $sha1` 7 | if [ "$1" ]; then 8 | if [ $TYP == "$1" ]; then 9 | echo "====================================================" 10 | echo $TYP $sha1; 11 | echo 12 | git cat-file -p $sha1; 13 | fi 14 | else 15 | echo $TYP $sha1; 16 | fi 17 | 18 | 19 | done; -------------------------------------------------------------------------------- /git-stat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | stat() { 4 | echo -n Number of revisions:; 5 | git log --oneline | wc -l; 6 | echo -n Number of developers:; 7 | git shortlog -s | wc -l; 8 | echo -n Number of days:; 9 | git days | wc -l; 10 | echo -n The working directory:; 11 | du -h -s --exclude=.git; 12 | echo -n The git directory:; 13 | du -h -s .git; 14 | echo -n Number of files in the working dir:; 15 | git ls-files | wc -l; 16 | }; 17 | 18 | stat 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013 Włodzimierz Gajda 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | git config --global alias.s "status -sb" 5 | git config --global alias.l "log --oneline --decorate" 6 | git config --global alias.g "log --oneline --decorate --graph" 7 | git config --global alias.b "branch" 8 | git config --global alias.snapshot "!snapshot() { COMMENT=wip; if [ \"\$*\" ]; then COMMENT=\"\$*\"; fi; git add -A; git commit -m \"\$COMMENT\"; }; snapshot" 9 | git config --global alias.backup "!backup() { git snapshot \"\$*\"; git push; }; backup" 10 | git config --global alias.create-file "!createFile() { for name in \"\$@\"; do echo \$name>\$name.txt; done; }; createFile" 11 | git config --global alias.simple-commit "!simpleCommit() { for name in \"\$@\"; do git create-file \"\$name\"; git snapshot \$name; done; }; simpleCommit" 12 | git config --global alias.simple-loop "!simpleLoop() { NAME=\$1; i="1"; while [ \$i -le \$2 ]; do git simple-commit \$NAME\$i; i=\$[\$i+1]; done; }; simpleLoop" 13 | git config --global alias.multi-commit "!multiCommit() { for name in \"\$@\"; do git create-file $name; done; git snapshot \"\$*\"; }; multiCommit" 14 | git config --global alias.empty-commit "!emptyCommit() { git commit --allow-empty -m \"Empty commit\"; }; emptyCommit" 15 | git config --global alias.empty-init "!emptyInit() { git init ; git commit --allow-empty -m \"Initial empty commit\"; }; emptyInit" 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /alias.txt: -------------------------------------------------------------------------------- 1 | # ===[ALIAS-START]=== 2 | # 3 | 4 | 5 | [alias] 6 | c = config -l 7 | s = status -sb 8 | l = log --pretty=oneline --abbrev-commit --abbrev=4 --decorate -25 9 | ll = log --pretty=oneline --abbrev-commit --abbrev=4 --decorate 10 | g = log --pretty=oneline --abbrev-commit --abbrev=4 -25 --graph --decorate 11 | gg = log --pretty=oneline --abbrev-commit --abbrev=4 --graph --decorate 12 | rp = rev-parse --short=4 13 | b = branch 14 | ss = !git snapshot 15 | save = !git snapshot 16 | 17 | 18 | # General purpose aliases: 19 | # snapshot 20 | # backup 21 | # stat 22 | # days 23 | # 24 | # Educational aliases: 25 | # create-file 26 | # simple-commit 27 | # multiple-commit 28 | # simple-loop 29 | # simple-loop2 30 | # clear 31 | # branches 32 | 33 | 34 | # Alias: snapshot 35 | # Example: 36 | # 37 | # git snapshot This is my very important commit... 38 | # git snapshot "This is my very important commit..." 39 | # git snapshot 40 | # 41 | snapshot = "!snapshot() { COMMENT=wip; if [ \"$*\" ]; then COMMENT=\"$*\"; fi; git add -A; git commit -m \"$COMMENT\"; }; snapshot" 42 | 43 | 44 | # Alias: backup 45 | # Example: 46 | # 47 | # git backup This is my very important commit... 48 | # git backup "This is my very important commit..." 49 | # 50 | backup = "!backup() { git snapshot \"$*\"; git push; }; backup" 51 | 52 | 53 | # Alias: days 54 | # Example: 55 | # 56 | # git days 57 | # 58 | days = "!days() { git log --pretty=format:%cd --date=short | uniq; }; days" 59 | 60 | 61 | # Alias: stat 62 | # Example: 63 | # 64 | # git stat 65 | # 66 | stat = "!stat() { echo -n Number of revisions:; git log --oneline | wc -l; echo -n Number of developers:; git shortlog -s | wc -l; echo -n Number of days:; git days | wc -l; echo -n The working directory:; du -h -s --exclude=.git; echo -n The git directory:; du -h -s .git; echo -n Number of files in the working dir:; git ls-files | wc -l; }; stat" 67 | 68 | 69 | # Alias: create-file 70 | # Example: 71 | # 72 | # git create-file lorem 73 | # git create-file lorem ipsum dolor 74 | # 75 | create-file = "!createFile() { for name in \"$@\"; do echo $name>$name.txt; done; }; createFile" 76 | 77 | 78 | # Alias: simple-commit 79 | # Example: 80 | # 81 | # git simple-commit a 82 | # git simple-commit a b c 83 | # 84 | simple-commit = "!simpleCommit() { for name in \"$@\"; do git create-file \"$name\"; git snapshot $name; done; }; simpleCommit" 85 | 86 | 87 | # Alias: multiple-commit 88 | # Example: 89 | # 90 | # git multi-commit lorem 91 | # git multi-commit lorem ipsum dolor 92 | # 93 | multi-commit = "!multiCommit() { for name in \"$@\"; do git create-file $name; done; git snapshot \"$*\"; }; multiCommit" 94 | 95 | 96 | # Alias: simple-loop 97 | # Example: 98 | # 99 | # git simple-loop lorem 5 100 | # 101 | simple-loop = "!simpleLoop() { NAME=$1; i="1"; while [ $i -le $2 ]; do git simple-commit $NAME$i; i=$[$i+1]; done; }; simpleLoop" 102 | 103 | 104 | # Alias: simple-loop2 105 | # Example: 106 | # 107 | # git simple-loop2 lorem 7 13 108 | # 109 | simple-loop2 = "!simpleLoop2() { NAME=$1; i=$2; while [ $i -le $3 ]; do git simple-commit $NAME$i; i=$[$i+1]; done; }; simpleLoop2" 110 | 111 | 112 | # Alias: branches 113 | # Example: 114 | # 115 | # git branches lorem ipsum dolor 116 | # 117 | branches = "!branches() { for name in \"$@\"; do git branch $name; done; }; branches" 118 | 119 | 120 | 121 | # Clonning with remote branches 122 | # 123 | # Command to list remote branches: 124 | # 125 | # git branch -r | sed "/->/d; s/ origin\///g" 126 | # 127 | list-remote-branches = "!listRemoteBranches() { git branch -r | sed \"/->/d; s/ origin\\///g\"; }; listRemoteBranches" 128 | checkout-remote-branches = "!checkoutRemoteBranches() { for name in `git list-remote-branches`; do git checkout $name; done; }; checkoutRemoteBranches" 129 | # 130 | # Example: 131 | # 132 | # git clone-with-branches dirSrc dirDest 133 | # 134 | clone-with-branches = "!cloneWithBranches() { git clone $1 $2; cd $2; git checkout-remote-branches; git remote rm origin; }; cloneWithBranches" 135 | 136 | #@todo: check parameters: 137 | # git clone-with-branches URL 138 | 139 | 140 | 141 | # Example: 142 | # 143 | # git checkout beta 144 | # git set-version 0.1.0 145 | # 146 | # assumptions: 147 | # - clean repo 148 | # 149 | # @git get-version === cat version.txt 150 | 151 | set-version = "!setVersion() { echo $1 > version.txt; git snapshot Version $1; git tag -a v$1 -m \"Release $1\"; }; setVersion" 152 | get-version = "!getVersion() { cat version.txt; }; getVersion" 153 | 154 | 155 | 156 | # Remove old commits 157 | # 158 | # git clear-reflog-now 159 | # 160 | clear-reflog-now = "!clearReflogNow() { git reflog expire --all --expire=now; }; clearReflogNow" 161 | remove-old-commits = "!removeOldCommits() { git clear-reflog-now; git prune; }; removeOldCommits" 162 | 163 | 164 | # 165 | # ===[ALIAS-STOP]=== 166 | 167 | -------------------------------------------------------------------------------- /git-swapid: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Script to swap git/ssh identities. 4 | # It affects two files: 5 | # ~/.gitconfig 6 | # ~/.ssh/config 7 | # 8 | # You need at least two private RSA keys for your identity. 9 | # I assume that your keys are stored in: 10 | # 11 | # /home/john/.ssh/john 12 | # /home/john/.ssh/peter 13 | # 14 | # 15 | # All your identities are stored within .gitconfig. 16 | # 17 | # Add your adentities to your ~/.gitconfig file like in the following listing. 18 | # Every login has to be exactly the same as its key given in [identity "..."]. 19 | # If you define identity [identity "foo"] its login has to be "foo". 20 | # 21 | # # extract from ~/.gitconfig 22 | # [identity "john"] 23 | # name = John Doe 24 | # email = john@example.net 25 | # key = /home/john/.ssh/john 26 | # login = john 27 | # 28 | # [identity "peter"] 29 | # name = Peter Nobody 30 | # email = peter@some.other.host.example.com 31 | # key = /home/john/.ssh/peter 32 | # login = peter 33 | # 34 | # 35 | # Swapid entry is appended at the end of .ssh/config. 36 | # It will be the last effort entry. 37 | # If you have .ssh/config entries like in: 38 | # 39 | # # extract from ~/config 40 | # Host some-label 41 | # HostName example.com 42 | # User john 43 | # IdentityFile ~/.ssh/john_id_rsa 44 | # 45 | # Host lorem 46 | # HostName ipsum.com 47 | # User sarah 48 | # IdentityFile ~/.ssh/sarah_id_rsa 49 | # 50 | # Host * 51 | # IdentityFile ~/.ssh/another_id_rsa 52 | # 53 | # Then: 54 | # ssh -T some-label --> john@example.com using john_id_rsa 55 | # ssh -T lorem --> sarah@ipsum.com using sarah_id_rsa 56 | # ssh -T me@ble --> me@ble using another_id_rsa 57 | # 58 | # (C) 2013 gajdaw 59 | # 60 | 61 | if [ "$#" -gt 1 ]; then 62 | echo "***** ERROR: Too many arguments!" 63 | exit 64 | fi; 65 | 66 | if [ "$#" -eq 1 ]; then 67 | MYID=$1 68 | else 69 | # set default identity if possible 70 | MYID=`git config --global user.login` 71 | 72 | if [ ! $MYID ]; then 73 | echo "***** ERROR: Global user.login not set!" 74 | echo "***** ERROR: git swapid called without parameters needs default identity!" 75 | exit 76 | fi; 77 | fi; 78 | 79 | if [ ! $MYID ]; then 80 | echo "***** ERROR: The identity cannot be a null string!" 81 | exit 82 | fi; 83 | 84 | USER_NAME=`git config --global user.name` 85 | USER_EMAIL=`git config --global user.email` 86 | USER_LOGIN=`git config --global user.login` 87 | 88 | MYID_NAME=`git config --global identity.$MYID.name` 89 | MYID_EMAIL=`git config --global identity.$MYID.email` 90 | MYID_KEY=`git config --global identity.$MYID.key` 91 | MYID_LOGIN=`git config --global identity.$MYID.login` 92 | 93 | echo "Configuration read from ~/.gitconfig" 94 | echo " user.name = $USER_NAME" 95 | echo " user.email = $USER_EMAIL" 96 | echo " user.login = $USER_LOGIN" 97 | echo " " 98 | echo " identity.$MYID.name = $MYID_NAME" 99 | echo " identity.$MYID.email = $MYID_EMAIL" 100 | echo " identity.$MYID.key = $MYID_KEY" 101 | echo " identity.$MYID.login = $MYID_LOGIN" 102 | echo " " 103 | echo "Configuration read from ~/.ssh/config" 104 | grep -E "^ IdentityFile [^ ;]*$" ~/.ssh/config 105 | echo " " 106 | 107 | 108 | #if [ "$MYID_NAME $MYID_EMAIL $MYID_KEY $MYID_LOGIN" == " " ]; then 109 | # echo " * Initialazing $MYID identity" 110 | # git config --global identity.$MYID.name "John Doe" 111 | # git config --global identity.$MYID.email john@example.net 112 | # git config --global identity.$MYID.key ~/.ssh/john_id_rsa 113 | # git config --global identity.$MYID.login $MYID 114 | 115 | # MYID_NAME=`git config --global identity.$MYID.name` 116 | # MYID_EMAIL=`git config --global identity.$MYID.email` 117 | # MYID_KEY=`git config --global identity.$MYID.key` 118 | # MYID_LOGIN=`git config --global identity.$MYID.login` 119 | #fi; 120 | 121 | 122 | # We expect all four not null global git config settings for this id 123 | if [ ! "$MYID_NAME" ]; then 124 | echo "***** ERROR: Problem with git global configuration: identity.$MYID.name" 125 | echo " " 126 | echo "You can set it with:" 127 | echo " \$ git config --global identity.$MYID.name \"John Doe\"" 128 | exit; 129 | fi 130 | if [ ! $MYID_EMAIL ]; then 131 | echo "***** ERROR: Problem with git global configuration: identity.$MYID.email" 132 | echo " " 133 | echo "You can set it with:" 134 | echo " \$ git config --global identity.$MYID.email john@example.net" 135 | exit; 136 | fi 137 | if [ ! $MYID_KEY ]; then 138 | echo "***** ERROR: Problem with git global configuration: identity.$MYID.key" 139 | echo " " 140 | echo "You can set it with:" 141 | echo " \$ git config --global identity.$MYID.key ~/.ssh/john_id_rsa" 142 | exit; 143 | fi 144 | if [ ! $MYID_LOGIN ]; then 145 | echo "***** ERROR: Problem with git global configuration: identity.$MYID.login" 146 | echo " " 147 | echo "You can set it with:" 148 | echo " \$ git config --global identity.$MYID.login $MYID" 149 | exit; 150 | fi 151 | 152 | if [ ! -f $MYID_KEY ]; then 153 | echo "***** ERROR: The private key does not exist!" 154 | echo "***** ERROR: Filename: $MYID_KEY" 155 | echo "" 156 | fi 157 | 158 | if [ ! $MYID_LOGIN == $MYID ]; then 159 | git config --global identity.$MYID.login $MYID 160 | MYID_LOGIN=$MYID 161 | echo " * Resetting LOGIN in ~/.gitconfig for $MYID" 162 | fi 163 | 164 | # without parameters only print current settings 165 | if [ "$#" -eq 0 ]; then 166 | exit 167 | fi; 168 | 169 | # Everything is fine. Swap the identity 170 | 171 | # swap global git config 172 | git config --global user.name "$MYID_NAME" 173 | git config --global user.email $MYID_EMAIL 174 | git config --global user.login $MYID_LOGIN 175 | 176 | 177 | # swap private key in .ssh/config 178 | SSH_CONFIG_LINE=" IdentityFile $MYID_KEY" 179 | ESCAPED="$(echo "$SSH_CONFIG_LINE" | sed -e 's/[\/&]/\\&/g')" 180 | 181 | # does the .ssh/config exists? 182 | if [ ! -f ~/.ssh/config ]; then 183 | echo " * Creating ~/.ssh/config" 184 | echo "#swapid" > ~/.ssh/config 185 | echo "Host *" >> ~/.ssh/config 186 | echo "$SSH_CONFIG_LINE" >> ~/.ssh/config 187 | else 188 | 189 | # Does ~/.ssh/config contain our IdentityFile? 190 | WASIUSED=`grep -E "^ IdentityFile [^ ;]*$" ~/.ssh/config | wc -l` 191 | if [ $WASIUSED -eq 0 ]; then 192 | # no, there isn't IdentityFile entry matching swapid RE in .ssh/config 193 | echo "***** ERROR: Was .ssh/config used by swapid before?" 194 | echo "***** ERROR: Check .ssh/config - look for #IdentityFile" 195 | 196 | # Is there a commented IdentityFile line? 197 | WASIUSED_COMMENTED=`grep -E "^# IdentityFile [^ ;]*$" ~/.ssh/config | wc -l` 198 | if [ $WASIUSED_COMMENTED -eq 0 ]; then 199 | 200 | echo "#swapid" >> ~/.ssh/config 201 | echo "Host *" >> ~/.ssh/config 202 | echo "$SSH_CONFIG_LINE" >> ~/.ssh/config 203 | else 204 | # modify commented IdentityFile line with new id 205 | sed -i "s/^# IdentityFile [^ ;]*$/#$ESCAPED/g" ~/.ssh/config 206 | fi; 207 | else 208 | # yes, there is IdentityFile entry matching RE in .ssh/config 209 | echo " * Modifying ~/.ssh/config" 210 | sed -i "s/^ IdentityFile [^ ;]*$/$ESCAPED/g" ~/.ssh/config 211 | fi; 212 | fi; 213 | --------------------------------------------------------------------------------