18 Git and GitHub 0 comments
After using SVN for a year or two, I was reluctant to make the switch to Git, and I know it can be a daunting idea for anyone who has not used a version management system before, with the forking, branching, merging, differences and the like, but it really isn't difficult, so I thought I'd give the lowdown on how to get yourself setup for mobile programming using Git and Github.
Installing Git
For a start you will need to download the Git source from git.or.cz, then simply Google for guides on installing it on your operating system be it Mac OS X, Linux or Windows.
I am no master of compiling using the command line, but most others will provide a step-by-step guide with the exact commands you need to run.
Using Git
This is where Git really comes into it's own. Rather than going into the complicated SVN procedure of creating a repository and checking in and out before you can do anything. Git repositories can be started in place with nothing more than:
git init
So if you're using Rails, simply change directory to your Rails app then run the above command.
You will then want to setup Git to ignore some files, so create a .gitignore file and open it up in your text editor:
touch .gitignore
mate .gitignore
Now on each line you can add file strings to ignore, here is an example of my default Rails ignore file:
.DS_Store
*/.DS_Store
log/*.log
db/*.sqlite3
db/schema.rb
tmp/*
Save the file, and we are ready to add our files to the repository using:
git add .
Then you can run your commit to send them to the repository:
git commit -a -m 'My first commit'
Now your files are in the repository but that isn't much use unless you send it to a remote server for backup, or downloading at multiple locations, so on to GitHub.
Working with GitHub
GitHub provides hosted repositories so your projects can be backed up and more importantly accessed by others in your development team. The service is free for open source projects, however if you want to have a private repository then you can for the mere cost of $7 a month, a price nobody can argue with.
There is all the usual integration, with Twitter, Lighthouse, Basecamp and more, so you can stay clued up on what is going on within your project without having to reload the website every 10 minutes.
Again, setting up the remote repository can be a scary task, but GitHub guides you through providing exactly what commands you need.
Once you have provided your SSH key (don't worry there is a guide for that too) and setup a repository on GitHub, you can link your local repo to it easily with:
git remote add origin git@github.com:GITHUB_USERNAME/GITHUB_REPO_NAME.git
Then a simple push command will upload all the latest commits to the service:
git push origin master
So now you are a fully fledged mobile / collaborative developer! How does it feel? Good right?
Re-downloading a Repository
This process is known as cloning, and is very simple. When you clone a repository, Git will download all the files you need into a new repository that goes by the same name as your remote one, so if on GitHub you have a project called "notes", Git will make a folder called notes automatically, so make sure the folder you are in when you make the clone, doesn't have a notes directory already.
git clone git@github.com:GITHUB_USERNAME/GITHUB_REPO_NAME.git
After running the command above, you can make your changes, commit some updates and then push back to GitHub.
So that's a basic introduction to using Git, you don't need to be confused with all the advanced features when you are just getting started so hopefully you found this helpful!