= заметки о `git` == инициализация репозитория === начиная с сервера * на сервере: `git init --bare project.git`; * на клиенте: `git clone server.name.tld:repo/git/project.git project`; * копируем содержимое исходников в директорию `project` и выполняем {{{#!bash git add . git commit -a -m "inital release" git push origin master }}} === начиная с клиента {{{#!bash cd project git init git add . git commit -a -m "inital release" git remote add origin server.name.tld:repo/git/project.git git push origin master }}} [[br]] == синхронизация всех веток в bare репозиториях {{{#!bash git clone --bare url local.git cd local.git git config --add remote.origin.fetch '+refs/*:refs/*' git fetch }}} [[br]] == pull all branches to local {{{#!bash git branch -a | sed -n \"/\\/HEAD /d; /\\/master$/d; /remotes/p;\" | xargs -L1 git checkout -t" }}} [[br]] == pull single branch to local `git checkout -t remotes/origin/` [[br]] == drop last `n` commits `git reset --hard HEAD~n` [[br]] == update branch to master and top up unpushed commits * `git pull --rebase origin master` - in not pushed branch with local only commits. if something already pushed to remote it will desynchronize local and remote sides. in this case use: * `git merge master` - merge master commits to selected branch or * `git rebase master` - rebase master commits to selected branch [[br]] == edit, reword, squash, fixup, drop last `n` commits `git rebase -i HEAD~n` [[br]] == grep commit contents `git log -p --all -G clean_empty_state` [[br]] == github enterprise behavior - create a merge commit: - merge all commits from source branch into the middle of target branch; - create merge commit on top of target branch with all source commits as parents; - squash and merge: - squash all source commits into single commit; - add resulting commit on top of target branch; - rebase ant merge: add all commits from source branch on top of target branch [[br]] == submodules === add {{{#!bash smp='ansible/roles/external/nginx-install' git submodule add git@github.com:nginxinc/ansible-role-nginx.git ${smp} git submodule set-branch --branch tags/0.19.1 -- ${smp} git add .gitmodules (cd ${smp} && git checkout tags/0.19.1) }}} === remove {{{#!bash git submodule deinit -f ${smp} git add .gitmodules git reset HEAD -- ${smp} git rm -f ${smp} rm -rf .git/modules/${smp} ${smp} }}}