├── .gitignore ├── README.md ├── git-kata-functions └── git-kata1 /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | out/ 3 | *.iml 4 | *.swp 5 | git-kata-directory/ 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kata Scripts For Git 2 | 3 | You want to learn Git by practicing it but cannot find an easy way to do it, right? 4 | 5 | Here is a very simple bash script that can be modified for any of your senario. 6 | 7 | Please create pull request if you notice any problems or you create any extra kata scripts. 8 | -------------------------------------------------------------------------------- /git-kata-functions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | 3 | number= 4 | root= 5 | upstream= 6 | 7 | function switch_branch() { 8 | local exists=`git show-ref refs/heads/$1` 9 | if [ ! -n "$exists" ]; then 10 | git branch $1 11 | echo "New $1 branch created" 12 | fi 13 | git checkout $1 14 | } 15 | 16 | function commit() { 17 | sleep 1 18 | echo "$2" >> $1 19 | git add $1 20 | git commit -m $2 21 | } 22 | 23 | function initial_commit() { 24 | echo "initial commit" >> file 25 | git add file 26 | git commit -m "initial commit" 27 | } 28 | 29 | function display_log() { 30 | log "$root/repo/user_$1.git" 31 | } 32 | 33 | 34 | function display_log_upstream() { 35 | cd "$root/server/upstream.git" 36 | echo "Upstream is ready for serving you for the kata" 37 | log "$root/server/upstream.git" 38 | } 39 | 40 | function log() { 41 | echo "" 42 | git log --branches --remotes --tags --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=iso 43 | echo "" 44 | echo "In order to go to repository, run this command: cd $1" 45 | } 46 | 47 | function setup() { 48 | DIRECTORY="git-kata-directory" 49 | 50 | if [ -d "$DIRECTORY" ] 51 | then 52 | rm -rf git-kata-directory/ 53 | echo "$DIRECTORY folder exists. Deleted." 54 | fi 55 | mkdir -p "$DIRECTORY" 56 | echo "New $DIRECTORY folder created" 57 | 58 | cd "$DIRECTORY" 59 | root=$(pwd) 60 | 61 | create_upstream 62 | } 63 | 64 | function create_upstream() { 65 | mkdir -p "$root/server/upstream.git" > /dev/null 2>&1 66 | cd "$root/server/upstream.git" 67 | git init --bare > /dev/null 2>&1 68 | echo "Upstream repository created" 69 | upstream=true 70 | } 71 | 72 | function switch_user() { 73 | if [ ! -d "$root/repo/user_$1.git" ] 74 | then 75 | mkdir -p "$root/repo/user_$1.git" 76 | cd "$root/repo/user_$1.git" 77 | git init 78 | git config user.name "User ${1}" 79 | git config user.email "user_${1}@git.kata" 80 | if [ -n "$upstream" ]; then 81 | git remote add origin "file://$root/server/upstream.git" 82 | fi 83 | else 84 | cd "$root/repo/user_$1.git" 85 | fi 86 | } 87 | -------------------------------------------------------------------------------- /git-kata1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | source git-kata-functions 3 | 4 | ############################################################################## 5 | # DESCRIPTION: 6 | # this kata simulates synchronizing feature branch with newly added commits 7 | # of source branch via rebase and updating the source branch without using 8 | # checkout command. This is one of the most used synchronizing senario. 9 | ############################################################################## 10 | 11 | setup 12 | 13 | ##################### 14 | switch_user tesla 15 | initial_commit tesla 16 | ##################### 17 | 18 | switch_branch feature 19 | commit "settings.xml" "adds configuration of the project" 20 | commit "procfile" "adds heroku settings to bootup with correct server configs" 21 | 22 | switch_branch master 23 | commit "readme" "creates an initial readme to add proper documentation" 24 | commit ".gitignore" "adds initial gitignore file to ignore irrelevant files from git" 25 | 26 | git push -u origin feature 27 | git push -u origin master 28 | display_log tesla 29 | 30 | ##################### 31 | switch_user edison 32 | ##################### 33 | 34 | switch_branch master 35 | git pull origin master 36 | 37 | commit "file1" "creates file1" 38 | commit "file2" "creates file2" 39 | 40 | git push origin master 41 | display_log edison 42 | 43 | ##################### 44 | switch_user tesla 45 | ##################### 46 | 47 | switch_branch feature 48 | git pull --rebase origin master 49 | git push -f origin feature 50 | 51 | git fetch origin master:master 52 | display_log tesla 53 | --------------------------------------------------------------------------------