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

1,179 responses to “Git tutorial, getting started with Git”

  1. www.binance.com registrera dig Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  2. binance register Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/en/register-person?ref=JHQQKNKN

  3. hotel upselling techniques Avatar

    Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?

  4. Binance推荐 Avatar

    Your article helped me a lot, is there any more related content? Thanks!

  5. 开设Binance账户 Avatar

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/register-person?ref=IXBIAFVY

  6. https://atavi.com Avatar

    References:

    Slot machine winners

    References:
    https://peatix.com/user/29178303

  7. atavi.com Avatar

    References:

    Ellis island casino

    References:
    https://doc.adminforge.de/s/ZTWihMYl_a

  8. folkd.com Avatar

    References:

    Winnavegas casino

    References:
    http://madk-auto.ru/user/tieash8/

  9. justpin.date Avatar

    References:

    Windcreek casino atmore al

    References:
    https://myspace.com/goalsteel9

  10. lost Instagram account recovery Avatar

    Rattling excellent info can be found on site.

  11. iPhone data recovery hacker Avatar

    I’m not sure why but this site is loading very slow for me. Is anyone else having this issue or is it a issue on my end? I’ll check back later on and see if the problem still exists.

  12. http://115.175.67.190/ Avatar

    References:

    Another name for physiological risk is safety
    risk.

    References:
    https://www.atmasangeet.com/candymcinnes8

  13. 89.234.183.97 Avatar

    References:

    Mass building pills

    References:
    https://hanyunmedical.com/maloriemattner

  14. http://219.157.255.213 Avatar

    References:

    Different types of steroids and what do they do

    References:
    http://shinhwaspodium.com/bbs/board.php?bo_table=free&wr_id=4772804

  15. 182.92.251.55 Avatar

    References:

    Turinabol steroid

    References:
    http://39.101.170.62:9080/fionamojica357

  16. http://41.180.4.117/ Avatar

    References:

    Testosterone injections for muscle building

    References:
    http://139.196.211.140:3000/wilfordcamfiel

  17. git.janhrabal.com Avatar

    References:

    Oral steroids for muscle gain

    References:
    http://106.52.29.202:3000/joleenwalthall

  18. melhiqjobs.com Avatar

    References:

    Anabolic steroids high blood pressure

    References:
    https://fanajobs.com/profile/patriciapfeffe

  19. 139.196.179.195 Avatar

    References:

    How to take anadrol properly

    References:
    http://rm.runfox.com/gitlab/angelmccauley

  20. Binance 註冊 Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.com/zh-TC/register?ref=DCKLL1YD

  21. Illuminati uk Avatar

    Thanks for sharing superb informations. Your web site is so cool. I am impressed by the details that you’ve on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched everywhere and just could not come across. What a great web site.

  22. romania illuminati Avatar

    Great line up. We will be linking to this great article on our site. Keep up the good writing.

  23. binance h"anvisning Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://accounts.binance.com/register-person?ref=QCGZMHR6

  24. binance kod 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.

  25. skapa ett binance-konto Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  26. viagra online buy

    viagra online buy

  27. live nude chat Avatar

    Hi there would you mind stating which blog platform you’re working with?
    I’m planning to start my own blog in the near future but I’m having a
    hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your design and style
    seems different then most blogs and I’m looking for
    something completely unique. P.S Sorry for being off-topic but I had to ask!

  28. finasteride brand

    finasteride brand

  29. open a binance account Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.info/hu/register?ref=IQY5TET4

  30. meloxicam for pain in cats

    meloxicam for pain in cats

  31. binance- Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

Leave a Reply

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