When starting at Access I had no experience of 'version control', unlike everyone else, so I had to learn the basics quickly. This article shows my quick-start guide to setting up Git and how easy it is to use on a daily basis.
First, some basic concepts need to be explained:
For a project, your files are stored in a repository (or repo). You can have a repo on your local machine, on the machine of a team member, or on a hosted service such as GitHub or BitBucket (remote repo).
Git tracks the changes you make to your project files (edited, moved, renamed, deleted), this allows you to review what you can done before you commit the changes to your local repo, and then push the files onto your remote repo. Using the remote repo is not required if you work alone but is invaluable for team projects and as an off-site backup.
So, that's the basic concept, now follow the steps below to create a repo and connect it to a BitBucket account to start controlling your source code!
First download and install the latest version of Git, then open up your terminal.
Set a name and email for your local machine:
git config user.name "FIRST_NAME LAST_NAME" git config user.email "[email protected]"
Make a folder on your local machine to hold your project source and 'change directory' there:
mkdir my_project cd my_project
In your web browser, create a free BitBucket account and create a new repo for your project 'my_project'.
Back in terminal, initialise 'Git' on your project folder to begin tracking changes:
Next, add the your BitBucket repo as a 'remote origin' to allow you to push changes up to BitBucket:
git remote add origin http://email@example.com/my_username/my_project.git
Begin to code your project as normal. At any point you can access a list of modified files with this command:
Changes to your project must be 'staged' using the git add command before being committed:
git add .Using '.' will add all files in the local directory. Alternatively you can add single folders or files using the following:
git add images/* git add images/logo.jpg
If you stage a file by mistake you can reset it:
git reset images/logo.jpg
Commit files you have staged to your local repo using:
git commit -m "Added file, fixed #2"The '-m' sets a message to accompany your commit to describe the changes you made. Try to be a specific as possible and where relevant include issue numbers from a bug reporting system (the BitBucket website has one built in).
When you're ready to share your commits, you can push them up to your BitBucket remote repo:
git push -u origin master
The '-u' stores your branch names so future pushes can be completed using:
You will be prompted for a password associated with your BitBucket account. It appears as if you're not typing, but the text is hidden for security. Now your files are on the remote repo for other team members to pull down to work on themselves.
Continue making more changes to your project and when you're ready do another commit and push:
1 2 3
git add images/* git commit -m "Added photo gallery images" git push