02

Getting started with Git

Git is a free, high peformance, distributed version control system that was originally developed by Linus Torvalds during the development of the Linux kernel. This article provides a straightforward step by step approach to install and configure Git on your machine, as well as creating a GitHub online account and linking it to your local Git repository.

Installing Git (msysgit)

First of all to begin using Git on Windows, we need to download and install msysgit. To install, simply run the installer executable and select the default install options on each screen (you may want to uncheck the options for Windows Explorer integration options if your right-click menu is already cluttered). Once the installation is complete you should have a Git Start Menu item, where you will find Git Bash which is our Git command line. Now we just need to do some basic configuration before we start using Git.


Configuration

First of all what we want to do is add some basic details about ourselves to the global configuration file:

Open up Git Bash and type the following:
git config --global user.name "Your Name"
Then:
git config --global user.email youremail@domain.com

Now you should be able to navigate to your home directory (type %userprofile% in the address bar of explorer) and you should be able to see a file called .gitconfig (the file will be hidden so you may have to enable Show Hidden Files option via Tools -> Folder Options -> View).

You can check your settings have been added by running the following command within Git Bash, git config --list this will display all the configuration settings that Git is aware of (which includes not only the global .gitconfig file but also the gitconfig file which is located within <Git Installation Directory>\etc\).

The next step here is to create a user variable called HOME that provides the path to your user profile directory, this is required before generating your SSH Keys as the OpenSSH tools that come with Git require this variable to reference your user profile directory.

To do this right-click on My Computer - > Properties -> Advanced tab -> Environmental variables. Add a new user variable called HOME and set the value to %USERPROFILE% as I have.

 

Setup a GitHub account

GitHub is a web hosting service for Git projects where you can setup an account with a range of sizes and features available, depending on your requirements. For the purpose of this exercise I will be setting up a free GitHub account but you can check out all the options available here.

Before creating an account at GitHub, we first need to create an SSH key. To do this open Git Bash and run the following:

ssh-keygen -C "youremail@domain.com" -t rsa
Press enter to accept the default file name and location.
 

Note: If you wish to run Git via FinalBuilder or FinalBuilder Server do not specify a passphrase for your key as protected keys are not supported.

Again to see the files created go to your home directory and you should see a folder called .ssh (this is a hidden folder so you may need to enable the Show Hidden Files option to see it). Inside this folder there should be two files named id_rsa and id_rsa.pub.

For more help on SSH and generating keys see the GitHub help.

Now that you have your SSH keys setup you can go ahead and sign up for your GitHub account. Go to http://github.com/plans to sign up for an account, I will be creating a free one. At the following screen enter your details, where it asks for your SSH Public Key open your id_rsa.pub file (which contains your public key) and copy the contents into the field on the application form.

Click the I agree, sign me up! button and your done.

Once you have setup your account you should be directed to the Dashboard for your account. If not just click the Dashboard link at the top right of the page. At the dashboard select the Create a Repository link which will display the following screen.

Enter the details for your repository and click Create Repository. You should now be presented with a screen that provides steps of how to get up and running using Git and GitHub.

You can ignore the global setup because we have already done that, so now we can get on with setting up a Git Repository (following the Next steps section).

Setting up your local repository

The first step is to create a directory for our local repository to reside in. Using Windows explorer navigate to the C:\ drive and create a new folder called NewProject. Alternatively open Git Bash from the start menu and run:

cd C:
mkdir NewProject
cd NewProject

Now from Git Bash run:
git init

This will create a new repository in the NewProject folder. In Windows explorer open the NewProject folder and you should be able to see a directory .git inside, this is now your local repository.

Now we want to add a file to our local repository. Right click in the NewProject directory (not NewProject\.git\) and select New -> Text Document.  Add some text to this file (a few words will suffice), save the file as Readme.txt and close the file.

Now from Git Bash run git status, you should be able to see the following:

We can see from the output of Git that Readme.txt is currently untracked, to add the file to our repository we want to run the following command git add Readme.txt which stages our file for the next commit. We can see this by running git status again.

To commit this change to the Git repository we run git commit -m "This is my first commit". If you run git status one more time you can see that the changes have been committed and the working directory is now clean.

Next what we want to do is add the remote origin for our local repository. To do this we go back to our GitHub account and copy the private URL which has read and write access (you have to be logged in to see the private URL):

Then in Git Bash we run:

git remote add origin git@github.com:username/NewProject.git

What this does is set the remote origin for this particular repository, this is information is stored in the NewProject\.git\config file. You can use the git config --list to view these details:

The last step on our list of things to do is to push these changes back to our remote repository.  To do this we run the following command:

git push origin master

Once this command is run we should be able to see the result through Git Bash, now go to your GitHub page and view the Commits page for your repository you should be able to see something similar to this:

Git Bash

 

GitHub Source

 

GitHub Commits

You now have a local Git repository, which coupled with your GitHub account allow you to manage your code by

synchronising with the upstream repository, making changes locally, review and commit changes before pushing changes upstream.

You also have the ability to provide fellow developers access to your GitHub repository to enable team collaboration.

Git integration is available with Finalbuilder Version 7.
 

Posted in: FinalBuilder

Post Rating

Comments

pkellner
# pkellner
Thursday, December 13, 2012 12:13 PM
I don't see anything about finalbuilder here, just git

Post Comment

Only registered users may post comments.