Nominate our 2022 Qt Champions!

Qt and Git

  • I'm new to both Qt and Git, so this question could easily go on a newbie git form.

    What files should I be tracking in my project? The obvious answer is anything I want backed up; however, do I need all these extra files or just my code?

    For example, when I create a project Qt makes three directories: ProjectDir, ProjectDir-build, and ProjectDir-debug.
    Do I need to track all three of these directories? Or can I just track the main dir that has the .pro file, all my .cpp and .h files?

    This is my first Qt project, and first time using git. Any advice would be nice.

  • Just use git for your your ProjectDir, you don't need to use git in the other directories.
    If you find usefull, here is a cheat sheet of most comun 12 git comands I use.

    @Sets the name of the user for all git instances on the system

    $ git config --global "Firstname Lastname"
    $ git config --global ""

    1. start git in project directory:

    $ git init

    1. check project status

    $ git status

    1. add files for git tracking

    $ git add .


    $ git add -u
    (remove deleted files)

    1. take a snapshot of the tracked files

    $ git commit


    $ git commit -m "comments about the commit"

    1. check info about the commits

    $ git log

    1. check branchs in the project, at the beginning there will only be one, the master

    $ git branch

    1. create a new branch called authorization

    $ git branch authorization

    1. change to the new branch

    $ git checkout authorization

    1. Do the merge from branch authorization with the branch master
      Note: We should be in the master branch

    $ git merge authorization

    1. Now we can delete the authorization branch

    $ git branch -d authorization

    1. Create tags

    $ git tag -a v1.4 -m 'my version 1.4'

    1. Show all tags
      $ git tag

  • Don't forget
    @git merge --no-ff@
    ff stands for fast-forward.
    for merging topic branches when the dev hasn't advanced yet (or hotfix branches when the master hasn't advanced).

    and of course
    @git rebase@
    usually when you push to a remote repo which has advanced and you don't want to merge but ff.

    I suggest

    What might be helpful, too, here's my general .gitignore:
    @# OS Related:


    Qt Related:


    Compilation Binaries:

    more specialized gitignores are in subdirs where necessary.

    My .gitattributes is
    @* text=auto

    *.cpp text
    *.h text
    *.txt text
    *.html text
    *.xml text
    *.css text
    *.sh text
    *.py text

    *.png binary
    *.jpeg binary
    *.jpg binary
    *.bmp binary@
    (prevents windows users from messing up newlines with their crazy \r\n)

Log in to reply