Links are provided to other tutorials and other explanations.
I also use that page to join and publish a few configuration files to improve and customize your use of git, some advices, and some aliases to ease the use of git on the command line (thanks to your
~/.bash_aliases file for the command-line GNU/Bash environment).
This page, and all related files are freely distributed under the terms of the GPLv3 licence ! (like everything I publish or distribute).
What is Git ?¶
« Git is a decentralized version control software. This is free software created by Linus Torvalds, Linux kernel copyright and distributed under the terms of the GNU General Public License Version 2. »
« Git is designed to be efficient in speed and ensure the integrity of data stored, sent or received. Completely free and open-source since 2005, it quickly became the most popular version control system for software development. »
What’s the point?¶
« A version control software is a software designed to store a set of files by holding the chronology of all the changes that have been made on it. »
« git allows notably to find all the previous versions of a lot of related files. It also allows an effective and secure control of your files (and even of entire projects) and also provide a complete track changes made to each file. »
Needless to say, I am using git constantly, mainly when I work on Linux ((X)Ubuntu™ 15.10) on a daily basis, and from time to time on Windows™.
Is it really so popular?¶
An important distinction¶
A little loose, but still in the order from the best reference to the blurrier:
www.Atlassian.com/git/ covers lots of things. I like the graphic and English styles of these explanations,
the help.GitHub.com website is really well designed, and it can sure help you,
this project on GitHub is a git style guide, to help you learn how to correctly name your branches, commits etc, see this article by @agis,
Two documents in PDF to download in order to never panic when you will get lost during your first days with git:
Other resources (less useful, but can help):
Actively maintained. (November 2014)
For these two configuration files (on Linux), a global
.gitignore can be in your
/home/pseudo), and a particular file for every repository can also be created.
git-configis a git command, and it interacts with the file(s)
.gitconfig. The page git-scm.com/docs/git-config gives in-depth explanations on how to use a
.gitconfig. More details are also given here on the book on git-scm.com. These explanations by Atlassian or this small article by Nick Berardi can also help. Two other examples: GitHub.com/matagus/gitconfig, GitHub.com/alikins/gitconfig.
These explications on help.GitHub.com why and how to use
.gitignore. GitHub even offer a collection of .gitignore files suitable for different kinds of projects. For instance, that one is perfectly designed to use with a Python project.
- Punk Rock Git
From the Command Line¶
alias GitChanged='clear ; git status | grep --color=always 'modified' | less -r'for the modified files,
alias GitDeleted='clear ; git status | grep --color=always 'deleted' | less -r'for the deleted files,
alias GitAdded='clear ; git status | grep --color=always 'added' | less -r'for the added files,
alias GitSize='clear; git count-objects -v -H | grep "size-pack" | sed s/"size-pack: "/"The size of the repository is "/'displays the storage size of the current repository (e.g. 10.43 MB currently for this project web-sphinx).
$ git count-objects -v -H | grep "size-pack" | sed s/"size-pack: "/"The size of the repository is "/
The size of the repository is 17.33 Mio
These ones are good shortcuts, which by default also launches local compression of the just filed after each operation (on average it saves time):
alias Push='clear; git push && git gc'to upload the latest changes on the mother repository,
alias Pull='clear; git gc && git pull && git gc'to download the latest changes from the mother repository,
alias Commit='clear; git commit -m'to quickly validate the last changes (ie. doing a commit),
alias Add='git add'to easily add files,
alias Aggressive='git gc --aggressive'launches an « aggressive » compression,
alias s='clear ; git status | less -r'is a handy shortcut for the most used git command:
And finally, I have defined an practical alias to synchronize the current project with the deposit mother and its sub-folder on my website.
alias Sync='clear; echo -e "Synchronizing (git push, gc, send_zamok, send_dpt)…"; git push; git gc --aggressive; make send_zamok; make send_dpt; alert'
For instance, that repository is here locally on my website (publis/ansi-colors). That other one is here locally on my website (publis/Bomberman). And that last one is also here locally on my website (python-demos).
Details about aliases Bash?
More information is available in this book about Bash programming, on the Linux documentation project, that other doc, or that last Wikipédia about aliases on generic scripting programming language.
Git does * not * store compressed diffs, but entire files, at every release (in compressed form, okay)!
Contrary to what I believed for a long time (until 2020!), There is a difference between what git displays when we do a
git diff file and what git stores when we add this file in a new commit!
I thought for a long time that git stores the
diff, but actually no!
This is the biggest « urban legend » or misunderstanding on git, and I discovered my mistake thanks to this blog post on GitHub.blog (and this one too).
With Sublime Text 3¶
A graphical interface for git?
The use of any good GUI for git can save a lot of time. To write webpages and code, I like Sublime Text 3 (ST3). Regardless of your text editor or IDE, it should be possible to bring this kind of functionality to easily use git without always going through console commands.
The small GitGutter will help to visualize the difference of each line of each file regarding the last commited version for the git repository in which it is located (visually great to see the changes since the last commit).
The wonderful SublimeGit (installable from sublime.wbond.net/packages/SublimeGit). Allows a full integration of git via the control panel. Free but annoys you regularly to ask you buy an (useless) 10$ commercial licence… But it is really awesome, so you will support this.
GitSavvy seems to be a good free and open-source alternative.
GitHub offers pretty much the same (awesome) features, for free too.
Bitbucket offers in addition to the public repositories and unlimited numbers of private repos. Every repos is limited to 2GB (you really have to want to break the system go beyond!). Signing up is quick, just go to this page https://Bitbucket.org/ ! (Note that Bitbucket can also be used with a Google account, Facebook, GitHub or even with OpenID.)
Public deposits are visible to all: Bitbucket.org/lbesson/profile/repositories.
For example, here are some of my repositories:
Bitbucket.org/lbesson/bin hosts dozens of scripts, especially some in Bash and Python
Further reading is available here en.WikiPedia.org/wiki/Bitbucket.
Publish web pages with Bitbucket?¶
If your username is Bitbucket STUFF, it is possible to create a repository called « STUFF.bitbucket.org », and then all documents will be stored there you will be automatically available on the website http://STUFF.bitbucket.org !
See for example this little page lbesson.Bitbucket.org/README.html whose source is hosted here Bitbucket.org/lbesson/lbesson.bitbucket.org/src/master/README.html.
I mainly use lbesson.Bitbucket.org for:
squirt a bookmarklet for Firefox, Chrome or Opéra, allowing to read a webpage super fast (hey, by the way, it is available on that website also, go on, try by hitting the « q » on your keyboard! Cool right?),
StrapDown.js is a pretty project to quickly and easily write and publish responsive webpages, in Markdown. Such StrapDown-powered document are directly ready to be published like-this on any website or server, without any boring compilation step required by you ! (This project currently is only downloaded about 20 times a month, thanks to the zip archive StrapDown.js.zip),
My own copies of the (legendary) 2048 game: lbo.k.vu/2048 (the original one), lbo.k.vu/2048-agreg (a version for mathematicians) or the interesting lbo.k.vu/2048-AI (available with an Artificial Intelligence).
And even if the certificate is not valid, it is perfectly possible to use this feature with HTTPS activated: https://lbesson.Bitbucket.org/README.html (if your browser rattle and displays an error is perfectly normal!). If you are using a relatively new browser, it may grumble and explain why (you will see that the only reason is that the SSL certificat for https://bitbucket.org has been signed for only a few sub-domains of the website bitbucket.org, not all of them). But in fact the traffic will be well encrypted and secured by the SSL certificate, no worries :)
A French web interface for Bitbucket?¶
For a little over a year, it is possible to change the interface of the site in French (and many other languages) in your personal settings.
In March and April 2013, I initiated and for some time I managed the translation of the site and the service of the English into French. I translated almost 90% presque 90% du contenu initial, of the original content, left some small typos, but we did a good job. With few other motivated and myself, French was the first language translated to 100%! (Mid March 2013) I have neither the time nor the desire to take care of it, but the project continues to be maintained by others.
One last tip?¶
As with any technical and powerful software, git takes time to adapt. Be persistent, it is worth it.
« I wish you a very good programming experience, and good luck for your geeky projects! »
Thanks to Vincent Cohen-Addad for motivating me to start using git, in Octobre 2012 for the network programming project for my Computer Science (CS) Master of Science (MPRI, course #1-21) on which we worked together.