Learning more about git
If you are not familiar with git we suggest at least you learn the basics. The official and comprehensive man pages are included in the Git package itself. You can access to them with:
git --help git <command> --help
Quick Git Setup
Setup SSH Keys
You can use git with https, but this requires to insert the username and password every time you need to push on the server (and to fetch or pull if the repository is private). Using ssh will save you some precious time. In order to use ssh you have to create an ssh key and add it to your profile on GitHub.
Your Identity
The first thing you should do is to set your user name and e-mail address.
git config --global user.name "John Doe" git config --global user.email "john.doe@example.com"
Some Color
If you use git mostly from the command line, colors are very useful, you can enable them by running:
git config --global color.pager true git config --global color.ui auto
Push behavior
We suggest you set upstream as the default push behavior:
git config --global push.default upstream
Bash Prompt
Bash prompt can be tweaked to show you in which branch you are by using __git_ps1. For example you can replace your default prompt in your ~/.bashrc file with:
if [ "$color_prompt" == "yes" ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[00;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s)")\$ ' fi
Migrating from SVN to Git preserving history
Simple projects
If the history of the project you want to migrate is simple (i.e. the project or its files were never moved around the repository), you can use git-svn to perform the migration.
The first step is to create a text file (e.g. authors.txt) that lists all of the users that would appear in your SVN repository and shows what their names would be for Git. The format is 'svn-username = Real Name <email address>', like so:
mario-rossi = Mario Rossi <mario.rossi@iit.it> john-doe = John Doe <john@example.com>
Then, run the following commands:
mkdir my_project_svn cd my_project_svn git svn init http://svn.blah.com/blah/trunk/ --no-metadata git config svn.authorsfile ../authors.txt git svn fetch
If you missed to list a user, the process gets stopped, but you can recover it by filling in the missing information and call "git svn fetch" iteratively.
Once the migration is completed, my_project_svn will still contain references to the original SVN repository; to get rid of them do:
cd .. git clone my_project_svn my_project_git git remote remove origin
Finally, to publish my_project_git, create a brand new empty repository on your GitHub account and do:
git remote add origin https://github.com/my-git-account/my_project_git git push origin master
Complicated projects
For projects that are more complicated you should use svn2git.
This includes the following cases:
- The project folder was moved around.
- Some files that are in your project were moved from outside your project folder.
- You want to preserve svn branches or tags and convert them to git branches/tags.
svn2git is harder to use than git2svn, and it will require to download the whole robotcub repository revision database locally, and this will take time and disk space.
On the other side, once the database is downloaded the real migration is very fast because everything happens locally.
You can find some instructions and all the files used for the migration of some of the robotcub repositories: https://github.com/robotology-legacy/robotcub-ruleset
Recommended Tutorials
Try git in your browser:
http://try.github.com/
LearnGitBranching - Web application designed to help beginners grasp the powerful concepts behind branching
http://pcottle.github.io/learnGitBranching/
Git-it - Desktop application that teaches you how to use Git and GitHub on the command line
https://github.com/jlord/git-it-electron
More
Git homepage
http://git-scm.com/
A few more setup tricks can be found here:
http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup
A very comprehensive source of documentation is this:
http://git-scm.com/documentation
Git reference:
http://gitref.org/
A Visual Git Reference:
http://marklodato.github.io/visual-git-guide/index-en.html
If you are a subversion user, you might find useful this crash course for svn users. Please note that git and svn workflows are slightly different, this is only supposed to be used as reference.
http://git.or.cz/course/svn.html
Git documentation wiki (contains several links):
https://git.wiki.kernel.org/index.php/GitDocumentation
CMake Git resources (more links):
http://www.cmake.org/Wiki/Git/Resources
A completely self-maintained and independent list of git tips and tricks made by Alessandro Roncone for his personal use (but useful nonetheless):
http://alecive.github.io/blog/2015/07/08/GitHubTricks/
More links:
http://git-scm.com/documentation/external-links
More tutorials can be found here:
http://sixrevisions.com/resources/git-tutorials-beginners/
Interesting Readings
7 Git personalities, which one are you? (Suggestions to avoid common mistakes)
https://about.gitlab.com/2015/01/27/7-git-personalities/