```bash
cp -R /usr/doc/git-2.14.4/contrib/git-shell-commands /var/git
chown -R git:git /var/git
-
```
Now we have 2 commands inside the git-shell-commands directory, list and help, the first will show all projects inside the /var/git directory and the other will show a simple help text and a list of all the commands available. Now to give you an example of how easy it is to add commands to the git-shell I will create a simple command that acts as the clear command, it will clean the screen, to do so, from inside the /var/git directory I did:
```bash
echo $(which clear) > git-shell-commands/clear
chmod 0755 git-shell-commands/clear
-
```
and now I have a "clear" command available for my git user. Another useful command will be "create" to add a repository and a "destroy" to remove it. Let's see them in the next page.
### create
-{{< highlight bash "linenos=table" >}}
+```bash
#! /bin/bash
# usage: create <PROJECT> - create a git bare repository named PROJECT.git
esac
fi
fi
-{{< /highlight >}}
+```
This is the create script, as you can see it's a bit complex because it will do a few things for me:
So after saving this script as create inside the git-shell-commands directory, we'll give it executable permissions and we can move to the delete script.
-{{< highlight bash >}}
+```bash
cat create-bare-repo.sh > /var/git/git-shell-commands/create
chown git:git -R /var/git/git-shell-commands
chmod 0755 /var/git/git-shell-commands/create
-{{< /highlight >}}
+```
### delete
Let's see the delete script:
-{{< highlight bash "linenos=table" >}}
+```bash
#! /bin/bash
+
# usage: delete <REPOSITORY> - PERMANENTLY delete a repository if existing.
# CAREFUL, this action cannot be undone. This command will ask for confirmation.
exit 177
fi
fi
-{{< /highlight >}}
+```
This script is much simpler than the previous one, it'll accept the name of the project as argument on the command line or will ask for it and will only delete it if it is a proper git repository, otherwise it will just exit with an error code.
Since we are here let's modify the help command to make it show a short description of every available command.
-{{< highlight bash "linenos=table" >}}
+```bash
#!/bin/sh
# usage: help - Lists all the available commands
esac
done
fi
-{{< /highlight >}}
+```
The main thing I added is the support for a command line argument, now I'm able to run it by itself and display the usual output with a list of available commands, or followed by a command name to give a brief explanation like this:
-{{< highlight bash >}}
+```bash
git> help
Hi git, Run 'help' for help, 'help <command>' for specific help on a command, run 'exit' to exit. Available commands:
clear
usage: create - create a git bare repository named PROJECT.git
this command will setup the repo and send a mail for confirmation.
git>
-{{< /highlight >}}
+```
Pretty nice isn't it?! Now it's much more user friendly, and to show the description I used awk and cut to parse the comment at the top of every script I have in the `git-shell-commands` directory.
Let's say I had a new idea for a WordPress plugin, I can't wait to start writing, so the setup of the GIT environment should be as fast as possible. That's where my setup will come in handy. Let's open the terminal, I'll go inside my testing directory and from there I'll run:
-{{< highlight bash >}}ssh git_ssh 'create awesomePlugin'
+```bash
+ssh git_ssh 'create awesomePlugin'
creating project "awesomePlugin.git"
Initialized empty Git repository in /var/git/awesomePlugin.git/
All done, you can now work on "awesomePlugin.git"
-{{< /highlight >}}
+```
The project is created, now I just need to clone it
-{{< highlight bash >}}git clone ssh://git_ssh:/var/git/awesomePLugin.git
+```bash
+git clone ssh://git_ssh:/var/git/awesomePLugin.git
Cloning into 'awesomePlugin'...
warning: Looks like you cloned an empty repository.
-{{< /highlight >}}
+```
And that's it, I now have a local and a remote copy of my git repository ready to work with.
Inside the deploy.sh script I'll edit those 2 lines:
-{{< highlight bash >}}# Directory where to deploy files from repository
+```bash
+# Directory where to deploy files from repository
DPTARGET=""
# Branch that is going to be deployed to server
DPBRANCH="master"
-{{< /highlight >}}
+```
adding `/var/www/wp-content/plugins/awesomePlugin` as `DPTARGET` and production as `DPBRANCH`.
now on my local system I'll add a new branch and use that before committing my stable code.
-{{< highlight bash >}}git checkout -b production
+```bash
+git checkout -b production
Switched to a new branch 'production'
git add .
remote: \==============================
To ssh://git_ssh:/var/git/awesomePlugin.git
* [new branch] production -> production
-{{< /highlight >}}
+```
And that's it, now my new plugin is ready to go live as soon as I activate it inside my WordPress admin area.