Skip to content

Perl web development – Step 1: Git

This is step 1 in the Perl web development series. In this step we focus on setting up Git for our web app.

Every single time I start a coding project, I setup a git repo to have version control. For most projects I don’t even really need version control but I almost always use 2 different branches to work in. The master branch and the develop branch. I think this is a good idea for every project, you have your master branch to commit your production ready code to and your develop branch to just fool around.

Setup your working directory

I always start with setting up a ‘container’ directory which holds all of my code. The Dancer app, the sqitch files, nginx files, etc. can be found directly under this directory. We are calling this app ‘Movie Collection’. In this case I make a directory called ‘MovieCollection’. As I work on Mac I will only show the steps needed for getting everything done on a Mac. For all steps there are plenty of articles available on google if you are dealing with another operating system.

Create the working directory

$ mkdir MovieCollection

Initiate Git repo

Now that we have a working directory, initiate a git repo.

$ cd MovieCollection
$ git init

The result should look like this

Initialized empty Git repository in /Users/***/Dev/MovieCollecion/.git/

If you get any errors about git not being an available command on you system, checkout this tutorial about installing git on your system.

Now that we have our git repo initiated it’s time for our first commit. Because I’m working on a Mac one the first the things I always do is make sure DS_Store files aren’t included in my repo. I use Vim as my editor but any editor will do.

$ vim .gitignore

*.DS_Store
:wq

This will make sure no .DS_Store files are included in the repo.

Initial commit

Now that we have a repo and actually added a file it’s to commit this file to the repo.
First step here is to check the status of your git repo. The command for this is something you must learn, never forget and embrace. It could save you a lot trouble in the future.

$ git status

The output would look something like this

git status
On branch master
Initial commit
Untracked files:
  (use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)

The output above tells us that we have a git repo, but no files are added yet to the repo. The .gitignore file we’ve just created is the first file we will be adding to the repo.

$ git add .gitignore

The output of git status should now look something like this.

$ git status
On branch master
Initial commit
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
new file:   .gitignore

As you can see the .gitignore file is added as a new file in the repo. Now it’s time for our first commit.

$ git commit -m"Added .gitignore file" .gitignore
[master (root-commit) 179059d] Added gitignore file
1 file changed, 1 insertion(+)
create mode 100644 .gitignore

And there you have it, the first step in your Perl web app.

Please leave a comment if you have any questions.

Published inCode