git
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| git [2011/07/21 16:45] – created k2patel | git [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== GIT Repository ====== | ====== GIT Repository ====== | ||
| + | |||
| + | ==== Setting up GIT ==== | ||
| + | === Create Server === | ||
| + | == Define User == | ||
| + | <code bash> | ||
| + | git config --global user.name " | ||
| + | git config --global user.email " | ||
| + | </ | ||
| + | |||
| + | == Create location for Repository == | ||
| + | <note tip> | ||
| + | <code bash> | ||
| + | mkdir -p / | ||
| + | cd / | ||
| + | </ | ||
| + | |||
| + | == Create bare repository == | ||
| + | <code bash> | ||
| + | git --bare init | ||
| + | </ | ||
| + | |||
| + | === Initial Synchronize with client === | ||
| + | == Initializing commit == | ||
| + | <note tip> | ||
| + | <code bash> | ||
| + | cd / | ||
| + | git init | ||
| + | git add . | ||
| + | git commit -m " | ||
| + | </ | ||
| + | |||
| + | == Define server and push files == | ||
| + | **For Local** | ||
| + | <code bash> | ||
| + | git remote add origin / | ||
| + | git push origin master | ||
| + | </ | ||
| + | |||
| + | **For Remote** | ||
| + | <code bash> | ||
| + | git remote add origin ketan@reposerver:/ | ||
| + | git push origin master | ||
| + | </ | ||
| ==== Backup ==== | ==== Backup ==== | ||
| Line 21: | Line 64: | ||
| <code bash> | <code bash> | ||
| cd ~/test.git | cd ~/test.git | ||
| - | git remote add --mirror git@backup.k2patel.com: | + | git remote add backup |
| + | git push backup | ||
| cat .git/config | cat .git/config | ||
| </ | </ | ||
| Line 32: | Line 76: | ||
| # | # | ||
| </ | </ | ||
| + | |||
| + | ==== Script for Backup ==== | ||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | #Build by. kpatel | ||
| + | # k2patel@hotmail.com | ||
| + | |||
| + | ## Nightly Backup of Repository. | ||
| + | |||
| + | ## Variables -- ( change According to your need ) | ||
| + | repohome=(/ | ||
| + | |||
| + | export receipients=" | ||
| + | |||
| + | ## Static | ||
| + | export git=$(which git) | ||
| + | |||
| + | ## Methods | ||
| + | notify(){ | ||
| + | for n in $receipients; | ||
| + | echo $1 | /bin/mail -s "[GIT] Backup $k2 Failed" | ||
| + | done | ||
| + | } | ||
| + | |||
| + | ## Programm | ||
| + | for k2 in ${repohome[@]}; | ||
| + | echo $k2 | ||
| + | if cd $k2 && $git push backup ; then | ||
| + | echo " | ||
| + | else | ||
| + | notify "GIT Backup Failed, $k2" | ||
| + | fi | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | ==== 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 ' | ||
| + | <code bash> | ||
| + | git reset --hard origin/ | ||
| + | git pull | ||
| + | </ | ||
| + | |||
| + | ===== Git Submodule ===== | ||
| + | |||
| + | ==== Clone Repository including submodule ==== | ||
| + | |||
| + | <code bash> | ||
| + | git clone --recursive git@github.com: | ||
| + | </ | ||
| + | |||
| + | ==== clone submodule from existing project ==== | ||
| + | |||
| + | <code bash> | ||
| + | git submodule update --init --recursive | ||
| + | </ | ||
| + | |||
| + | ==== To initialize single submodule ==== | ||
| + | <code bash> | ||
| + | git submodule update --init modules/ | ||
| + | </ | ||
| + | |||
| + | ==== Pull changes from all submodule ==== | ||
| + | <code bash> | ||
| + | git submodule foreach git pull origin master | ||
| + | </ | ||
| + | |||
| + | ==== Usefull when submodule HEAD and status HEAD messed up ==== | ||
| + | <code bash> | ||
| + | git submodule update --init | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
git.1311266739.txt.gz · Last modified: 2020/08/10 02:30 (external edit)
