User Tools

Site Tools


git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
git [2011/07/21 16:45]
k2patel created
git [2020/08/10 02:35] (current)
Line 1: Line 1:
 ====== GIT Repository ====== ====== 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 ==== ==== Backup ====
Line 21: Line 64:
 <code bash> <code bash>
 cd ~/test.git cd ~/test.git
-git remote add --mirror git@backup.k2patel.com:​test.git+git remote add backup ​--mirror git@backup.k2patel.com:​test.git 
 +git push backup
 cat .git/config cat .git/config
 </​code>​ </​code>​
Line 32: Line 76:
 #   ​mirror = true #   ​mirror = true
 </​code>​ </​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>​
 +
 +
 +
git.1311266739.txt.gz · Last modified: 2020/08/10 02:30 (external edit)