Skip to content

Commit de3bd82

Browse files
committed
Initial commit
0 parents  commit de3bd82

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Automated script for creating simple Git workflow
2+
3+
This project is in details described here [Create simple GIT workflow with automated script, like on GitHub].
4+
5+
![alt text](https://github.com/codingo-me/simple-git-workflow-script/raw/master/simple-git-completed.gif "Bash Script in Action")
6+
7+
Basic idea of this script is to skip using FTP/clients, scp or rsync for code upload to remote server. Instead this script will help you create robust Git workflow which involves protected bare Git repository and public repository which is served to visitors.
8+
9+
Public repository is mirror of bare repository. And bare repository is communication hub between your local development machine and public repository.
10+
11+
In couple of seconds you can create new repositories in a same way as you create them here on GitHub. One huge plus is that repository will be connected to public folder of your project via Git hooks.
12+
13+
14+
[Create simple GIT workflow with automated script, like on GitHub]:http://tuts.codingo.me/create-simple-git-workflow-with-automated-script-like-on-github/

basic-git.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
clear
3+
4+
#take path of public folder and create it
5+
echo "Please enter ABSOLUTE PATH of web server public folder for this project, that will be your publicly visible web folder (for Apache /var/www/html/...)"
6+
read webFolderPath
7+
while true; do
8+
read -p "You entered: $webFolderPath is that correct path? y/n?" yn
9+
case $yn in
10+
[Yy]* ) mkdir -p $webFolderPath; break;;
11+
[Nn]* ) echo "Script stopped"; exit;;
12+
* ) echo "Please answer yes or no.";;
13+
esac
14+
done
15+
16+
#cd into public folder and initialize git there
17+
cd $webFolderPath; git init;
18+
19+
#take path of bare git repository and create it
20+
echo "Please enter ABSOLUTE PATH of bare git repo, that will be you main entry point for pushing/pulling to remote server, one that ends with .git: "
21+
read gitBareRepo
22+
while true; do
23+
read -p "You entered: $gitBareRepo is that correct path? y/n?" yn
24+
case $yn in
25+
[Yy]* ) mkdir -p $gitBareRepo; break;;
26+
[Nn]* ) echo "Script stopped"; exit;;
27+
* ) echo "Please answer yes or no.";;
28+
esac
29+
done
30+
31+
#cd into git bare repository and initialize bare repository there
32+
cd $gitBareRepo; git init --bare;
33+
34+
#define bare repository as hub of public folder
35+
cat <<EOT > $webFolderPath"/.git/config"
36+
[remote "hub"]
37+
url = $gitBareRepo
38+
fetch = +refs/heads/*:refs/remotes/hub/*
39+
EOT
40+
41+
#create post-update hook in git bare repository, for syncing files with public folder
42+
cat <<EOT > $gitBareRepo"/hooks/post-update"
43+
#!/bin/sh
44+
echo
45+
echo "**** Pulling changes into Live [Hub's post-update hook]"
46+
echo
47+
cd $webFolderPath || exit
48+
unset GIT_DIR
49+
git pull hub master
50+
exec git-update-server-info
51+
EOT
52+
53+
#create post-commit to sync back with bare repository,
54+
#if you decide to change something directly from public folder
55+
cat <<EOT > $webFolderPath"/.git/hooks/post-commit"
56+
#!/bin/sh
57+
echo
58+
echo "**** pushing changes to Hub [Live's post-commit hook]"
59+
echo
60+
git push hub
61+
EOT
62+
63+
#take username that will use this repository
64+
echo -e "Please enter server username of user that will be using this repository: \c "
65+
read username
66+
67+
#add execute permission to 2 hooks
68+
sudo chmod +x $webFolderPath"/.git/hooks/post-commit";
69+
sudo chmod +x $gitBareRepo"/hooks/post-update";
70+
71+
#customize ownership over files
72+
sudo chown -R $username $webFolderPath;
73+
sudo chown -R $username $gitBareRepo;

simple-git-completed.gif

187 KB
Loading

0 commit comments

Comments
 (0)