Learning Git

If you want to learn more about Git, we recommend that you visit: book.git-scm.com/.

Some of the differences between Git and SVN are:

  • Your main Git directory is a full Git repository to which you can and must commit. In fact, we suggest you commit frequently.

  • When you commit, the commit goes into your local Git database. You must use another command to write it to the bacula.org repository (see below).

  • The local Git database is kept in the directory .git at the top level of the directory.

  • All the important Git configuration information is kept in the file .git/config in ASCII format that is easy to manually edit.

  • When you do a commit the changes are put in .git rather but not in the main bacula.org repository.

  • You can push your changes to the external repository using the command git push providing you have write permission on the repository.

  • We restrict developers just learning git to have read-only access until they feel comfortable with git before giving them write access.

  • You can download all the current changes in the external repository and merge them into your master branch using the command git pull.

  • The command git add is used to add a new file to the repository AND to tell Git that you want a file that has changed to be in the next commit. This has lots of advantages, because a git commit only commits those files that have been explicitly added. Note with SVN add is used only to add new files to the repo.

  • You can add and commit all files modifed in one command using git commit -a.

  • This extra use of add allows you to make a number of changes then add only a few of the files and commit them, then add more files and commit them until you have committed everything. This has the advantage of allowing you to more easily group small changes and do individaual commits on them. By keeping commits smaller, and separated into topics, it makes it much easier to later select certain commits for backporting.

  • If you git pull from the main repository and make some changes, and before you do a git push someone else pushes changes to the Git repository, your changes will apply to an older version of the repository you will probably get an error message such as:

    git push
    To git@github.com:bacula/bacula.git
     ! [rejected]        Branch-11.0 -> Branch-11.0 (non-fast forward)
     error: failed to push some refs to 'git@github.com:bacula/bacula.git'
    

    which is Git’s way of telling you that the main repository has changed and that if you push your changes, they will not be integrated properly. This is very similar to what happens when you do an “svn update” and get merge conflicts. As we have noted above, you should never ask Git to force the push. See below for an explanation of why.

  • To integrate (merge) your changes properly, you should always do a git pull just prior to doing a git push.

  • If Git is unable to merge your changes or finds a conflict it will tell you and you must do conflict resolution, which is much easier in Git than in SVN.

  • Resolving conflicts is described below in the github section.

Possible Next Steps

Go back to Git Usage.

Go back to Publishing Code.

Go back to Developer Guide.