This post provides a quick guide on how to set up and use a Git repository. I highly recommend using a Git repository in addition to backing up your files and database through a separate system. Git permits a lot of oversight and control over your code changes through time and can get your out of a pickle after something gets messed up or if you forgot what you did to the code a while back. Just think of it like DVR for your code. First we will set up a local GIT repository and then a remote one on either GitHub or BitBucket.
You will require an SSH command line interface to perform this. For Windows I recommend PuTTY a free SSH client. Linux and OSX include a client. GitHub offers a free Desktop client for those who do not wish to use SSH but I recommend at least getting familiar with the SSH methods.
Each $ sign indicates a discrete command. Copy the command without the $ sign and press return/enter before entering the next command.
System-wide Local Configurations for your Computer
$ git config --global user.name "Your Public Name"
$ git config --global user.email email@example.com
The above only need to be performed once per computer – Global to all local repositories.
Set up a New Local Repository
$ git init
If successful, you will see an output like this:
Initialized empty Git repository in /home/ubuntu/workspace/.git/
Optional – Add a Gitignore file
If working in WordPress, now is a good time to add a .gitignore file to the main directory for your workspace. Here’s a bare-bones version that supports some added privacy, security and saves on bandwidth usage for plugins and image uploadeds to your WordPress site. Save the file as “.gitignore” in your main directory.
Add Project Files
$ git add -A
Check Status of Repository
$ git status
You will see an output of those files that were just added. Use this command in the future to see where things stand in your repo.
On branch master
Changes to be committed:
(use "git rm --cached
new file: .gitignore
Make Your First Commit
This is a necessary step to actual commit the new files and changes to your repo.
$ git commit -a -m "First Commit!"
Add BitBucket (or GitHub, respectively) and Push Up to the Remote Repository
$ git remote add origin firstname.lastname@example.org:
$ git push -u origin --all
You will see an output similar to the one below after the push command:
If you now go to your Bitbucket or GitHub online repo you will see the new commit reflected there. Cool!