Git tutorial, getting started with Git

Below is a short comprehensive description of getting Git up and running in just a few minutes. I personally use OSX as a development machine and so the installation part of Git will cover an installation on OSX. If you like to install Git on another platform please take a look at the Git installation documentation. There are a lot of other ways to install Git, but the one described below seems to bring the least hassle on OSX.

Install Git and add your first project

  • First download the installer at the Google Git OSX installer project, http://code.google.com/p/git-osx-installer/downloads/list after running the installer you are good to go.
  • After this easy GUI installation it’s time to startup the terminal, although if you really are into GUI’s you can also download and install OpenInGitGui which can be found at http://code.google.com/p/git-osx-installer/wiki/OpenInGitGui. In your terminal go to the directory where your website is located and initialize a new repository here.

    $cd site_directory
    $git init

    You should now get a response like “Initialized empty Git repository in site_directory/.git/”. The next step is to add the current directory and all of its contents to the repository.

    $git add .
    $git commit -m "Initial import"

    You will now see that all files and directories are committed.

Basically this is it, nothing more to it. You could now start working with Git. Off course we can configure the Git installation just a little bit to set things right.

Basic configuration of Git, ignoring files and configuring the user settings
Whenever you will type “git status” on the current directory you will see if there are any changes that need to be committed, if so you can add them with the “commit” command like we did before. One of the first problems that you will bump into is that your cache files will also be committed. I personally don’t want to commit automatically created cache files or user content. So how can we deal with this? We can create a “.gitignore” file in the root of our project. You can find an example of the .gitignore file below.

*.cache
files

Now any file that has the *.cache extension will be ignored, also all the user content in the files directory will be ignored. This keeps our repository clean. By executing “git show” after committing the .gitignore file you will see that our ignore rules are correctly interpreted.

When you view the Git commit log of the project (“git log”) you will see that Git has already automatically used an author name and email address in the commits we did so far. These values are automatically detected by Git that examined your system configuration. You can change your name and email by executing the following commands:

$git config --global user.name Sjoerd Maessen
$git config --global user.email youremail@address.com

Taking advantage of Git
Off course we didn’t install Git just to add one project and change some basic settings. The power in any version control system is to make checkouts, revert and diff changes. Below you can find some basic commands that you will need to master.

$git checkout thepath
$git diff commitid1 commitid2
$git diff -- filepath
$git revert commitid1

The commands are pretty self explaining like all other commands of Git. If you already worked with other version control systems their is one thing to be aware of, “git revert” doesn’t behave like “svn revert” for example. “Git revert” will do a new commit to reverse a previous one, if you would like to undo your changes you should use “git checkout” instead. The things I have showed above are only small aspects of what Git is capable of. Cloning repo’s, tagging, branching, patching and resolving conflicts are all aspects that will make your life a lot easier, check them out at the Git community book

One more thing
There are some Git GUI repository browsers available that let you view who, why and when something was committed. One that is easy to setup and PHP only is viewgit, give it a try it will just run from your webserver!

http://viewgit.sourceforge.net

Comments

882 responses to “Git tutorial, getting started with Git”

  1. humanoïde robot Avatar

    Some genuinely nice and useful info on this site, besides I conceive the design holds fantastic features.

  2. binance register Avatar

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.info/cs/register-person?ref=OMM3XK51

  3. zaborna torilon Avatar

    I see something genuinely special in this website.

  4. containers Avatar

    I was curious if you ever thought of changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two pictures. Maybe you could space it out better?

  5. humanoid Avatar

    Once I initially commented I clicked the -Notify me when new feedback are added- checkbox and now each time a comment is added I get 4 emails with the identical comment. Is there any approach you can take away me from that service? Thanks!

  6. official here Avatar

    When someone writes an piece of writing he/she retains the thought of a user in his/her mind that how
    a user can know it. Thus that’s why this article is perfect.
    Thanks!

  7. apply free Avatar

    These are truly impressive ideas in on the topic of blogging.
    You have touched some fastidious things here. Any
    way keep up wrinting.

  8. official here Avatar

    You have made some really good points there. I looked
    on the web for more info about the issue and found most people will go along with your views on this web site.

  9. ShaneDrync Avatar
    ShaneDrync

    Awesome! Its truly amazing article, I have got much clear idea about from this piece of writing.
    byueuropaviagraonline

  10. zumospin Avatar

    Uitgebreide recensie van Zumospin Casino: licentie, spelaanbod, bonussen en mobiele app voor spelers uit Nederland. Welkomstbonus tot €150 + 200 spins.

  11. fdertolmrtokev Avatar

    Pretty nice post. I just stumbled upon your weblog and wished to say that I have truly enjoyed browsing your blog posts. After all I will be subscribing to your rss feed and I hope you write again soon!

  12. fdertolmrtokev Avatar

    Throughout this great design of things you’ll get a B+ with regard to effort. Exactly where you actually lost me personally ended up being on your facts. As it is said, details make or break the argument.. And it couldn’t be more true in this article. Having said that, permit me inform you what exactly did give good results. Your text is incredibly powerful and that is probably why I am taking the effort in order to comment. I do not make it a regular habit of doing that. Second, although I can easily see a leaps in reason you make, I am not confident of how you appear to connect the details which inturn make the conclusion. For now I will subscribe to your position but wish in the foreseeable future you link your facts better.

  13. Skapa personligt konto Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  14. Binance推荐码 Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  15. http://decoyrental.com Avatar

    References:

    Diamond jo casino northwood

    References:
    http://decoyrental.com

  16. md.swk-web.com Avatar

    References:

    Blackjack ski

    References:
    md.swk-web.com

  17. algowiki.win Avatar

    References:

    Soboba casino

    References:
    algowiki.win

  18. dakdekker amsterdam Avatar

    I have recently started a website, the info you provide on this website has helped me tremendously. Thanks for all of your time & work.

  19. feastbush81.werite.net Avatar

    References:

    Gaming machines

    References:
    feastbush81.werite.net

Leave a Reply

Your email address will not be published. Required fields are marked *