This shows you the differences between two versions of the page.
git [2016/06/08 15:37] k2patel [Git reset local] |
git [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== GIT Repository ====== | ||
- | |||
- | ==== Setting up GIT ==== | ||
- | === Create Server === | ||
- | == Define User == | ||
- | <code bash> | ||
- | git config --global user.name "k2patel" | ||
- | git config --global user.email "k2patel@live.com" | ||
- | </code> | ||
- | |||
- | == Create location for Repository == | ||
- | <note tip>replace location with your desired location</note> | ||
- | <code bash> | ||
- | mkdir -p /data/git/bumper.git | ||
- | cd /data/git/bumper.git | ||
- | </code> | ||
- | |||
- | == Create bare repository == | ||
- | <code bash> | ||
- | git --bare init | ||
- | </code> | ||
- | |||
- | === Initial Synchronize with client === | ||
- | == Initializing commit == | ||
- | <note tip>replace project location with desired location</note> | ||
- | <code bash> | ||
- | cd /data/project/bumper/ | ||
- | git init | ||
- | git add . | ||
- | git commit -m "Initial Commit" | ||
- | </code> | ||
- | |||
- | == Define server and push files == | ||
- | **For Local** | ||
- | <code bash> | ||
- | git remote add origin /data/git/bumper.git | ||
- | git push origin master | ||
- | </code> | ||
- | |||
- | **For Remote** | ||
- | <code bash> | ||
- | git remote add origin ketan@reposerver:/data/git/bumper.git | ||
- | git push origin master | ||
- | </code> | ||
- | |||
- | ==== Backup ==== | ||
- | To do backup on existing git repo please follow steps below.\\ | ||
- | Login to master machine.\\ | ||
- | Considering you already have key based access between master and backup server.\\ | ||
- | |||
- | == list available remote repository on master == | ||
- | <code bash> | ||
- | git remote -v | ||
- | </code> | ||
- | |||
- | == Now create bare repo on backup server== | ||
- | <code bash> | ||
- | cd $HOME | ||
- | git --bare init --shared test.git | ||
- | </code> | ||
- | |||
- | == On Master Server == | ||
- | after you taste your login. | ||
- | <code bash> | ||
- | cd ~/test.git | ||
- | git remote add backup --mirror git@backup.k2patel.com:test.git | ||
- | git push backup | ||
- | cat .git/config | ||
- | </code> | ||
- | |||
- | Result of last line should should contain text like the next block. | ||
- | <code text> | ||
- | # [remote "Backup"] | ||
- | # url = git@backup.k2patel.com:test.git | ||
- | # fetch = +refs/*:refs/* | ||
- | # mirror = true | ||
- | </code> | ||
- | |||
- | ==== Script for Backup ==== | ||
- | <code bash> | ||
- | #!/bin/bash | ||
- | #Build by. kpatel | ||
- | # k2patel@hotmail.com | ||
- | |||
- | ## Nightly Backup of Repository. | ||
- | |||
- | ## Variables -- ( change According to your need ) | ||
- | repohome=(/home/backup/test.git /home/backup/test2.git ) | ||
- | |||
- | export receipients="k2patel@sify.com k2patel@hotmail.com" | ||
- | |||
- | ## Static | ||
- | export git=$(which git) | ||
- | |||
- | ## Methods | ||
- | notify(){ | ||
- | for n in $receipients; do | ||
- | echo $1 | /bin/mail -s "[GIT] Backup $k2 Failed" $n | ||
- | done | ||
- | } | ||
- | |||
- | ## Programm | ||
- | for k2 in ${repohome[@]}; do | ||
- | echo $k2 | ||
- | if cd $k2 && $git push backup ; then | ||
- | echo "done" | ||
- | else | ||
- | notify "GIT Backup Failed, $k2" | ||
- | fi | ||
- | done | ||
- | </code> | ||
- | |||
- | ==== Git reset local ==== | ||
- | **following command can be used for following purpose :** \\ | ||
- | To discard all local changes and restore it to the remote repository.\\ | ||
- | When you have error //Your branch is ahead of 'origin/master'// | ||
- | <code bash> | ||
- | git reset --hard origin/master | ||
- | git pull | ||
- | </code> | ||
- | |||
- | ===== Git Submodule ===== | ||
- | |||
- | ==== Clone Repository including submodule ==== | ||
- | |||
- | <code bash> | ||
- | git clone --recursive git@github.com:k2patel/repo.git | ||
- | </code> | ||
- | |||
- | ==== clone submodule from existing project ==== | ||
- | |||
- | <code bash> | ||
- | git submodule update --init --recursive | ||
- | </code> | ||
- | |||
- | ==== To initialize single submodule ==== | ||
- | <code bash> | ||
- | git submodule update --init modules/repo | ||
- | </code> | ||
- | |||
- | ==== Pull changes from all submodule ==== | ||
- | <code bash> | ||
- | git submodule foreach git pull origin master | ||
- | </code> | ||
- | |||
- | ==== Usefull when submodule HEAD and status HEAD messed up ==== | ||
- | <code bash> | ||
- | git submodule update --init | ||
- | </code> | ||
- | |||
- | |||