Introduction in git """"""""""""""""""" About git ========= * source code management tool * stores your file in different versions * it's possible to sync your repo with a remote-repo over ssh/https * every checkout of a repo is a copy of the whole history why git & Ansible? ------------------ * who changed what * rollback to an other state * history of your changes * workflow for changes Links ----- * https://git-scm.com/doc * https://git-scm.com/book/de/v1 * https://git-scm.com/book/en/v2 * https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow/ * https://chris.beams.io/posts/git-commit/ git Basics ========== Repo / Checkout --------------- .. code-block:: bash # initialize a git repo git init # clone a repo git clone git@git.confirm.ch:pstauffer/ansible-training.git # checkout a branch / tag / commit git checkout file handling ------------- .. code-block:: bash # stage a file for the commit git add # add all files for the commit git add * # rename file git mv # delete a file git rm commit ------ .. code-block:: bash # commit a change (after the ``git add``) git commit -m 'commit message' Differences / Status -------------------- .. code-block:: bash # status git status # diff git diff # show history git log Remote Repo ----------- .. code-block:: bash # pull from remote repo git pull # push to remote repo git push # push a new branch git push -u origin newfeature # delete remote branch git push origin :newfeature Merge ----- .. code-block:: bash # merge actual branch with the newfeature branch git merge --no-ff newfeature Archive ------- .. code-block:: bash # export git repository git archive --format zip --output repo.zip master Branches / Tags =============== * use tags when you want a snapshot of the code as reference for the future * when you develop a new feature, create a new branch .. hint:: Create a master and develop branching model for your Ansible repository and create tags for stable releases. Branches -------- .. code-block:: bash # show all branches (incl. remote) git branch -a # checkout a branch git checkout # create a new branch git branch -b # delete a local branch git branch -d newfeature Tags ---- .. code-block:: bash # show all tags (incl. remote) git tag -a # create a new tag git tag -a v1.0 -m 'version 1.0 message' # remote push with tags git push --tags .. hint:: Use tags to create a snapshot of the code. Links ----- * http://nvie.com/posts/a-successful-git-branching-model/ * https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow Installation of git =================== On **Debian**-based Linux derivates .. code:: bash apt-get install git On **RedHat**-based Linux derivates .. code:: bash yum install git On **Mac OS X** with ``brew``. .. code:: bash brew install git .. hint:: In case ``brew`` cannot be found you've to install `Homebrew `_ first.