Skip to main content

Everything under Version Control - An Introduction to git and GitHub

·2 mins

In my last post “The Puppet Show”, I have written that I put all my code into a repository over at GitHub. This is a small write-up of how I did that.

Thanks to the book “Ruby on Rails 3 Tutorial” by Michael Hartl, I got a very nice intro to git. Those were my very first steps with git and the author did an excellent write-up that made those steps as easy as possible.

We need to do a one-time setup first. This has to be done on every new machine where you want to use git with.

{% highlight none %} git config –global user.name “Your Name” git config –global user.email [email protected] {% endhighlight %}

Then go into your project directory with all the files you want to have in version control.

{% highlight none %} git init {% endhighlight %}

Now add all your files with

{% highlight none %} git add . {% endhighlight %}

If you do

{% highlight none %} git status {% endhighlight %}

you will see all staged files that are ready to be committed. If you want to keep all the changes then commit them with

{% highlight none %} git commit -m “My initial commit” {% endhighlight %}

To see all your changes in the past do

{% highlight none %} git log {% endhighlight %}

Still, everything is on your hard disk only, but you want to share your code with other people, right?

Time to create your account over at GitHub.

After doing this and creating a new repository I got the following screen that actually tells me everything I need to know from there on. At least for the beginning.

So, let’s push everything to the repository.

{% highlight none %} git remote add origin [email protected]:/.git git push -u origin master {% endhighlight %}

Point your browser to your repository at GitHub and have a look.

Done for today!