wiki:notes/git

Version 11 (modified by root, at 2018-12-05T01:36:09Z) (diff)

--

заметки о git

инициализация репозитория

начиная с сервера

  • на сервере: git init --bare project.git;
  • на клиенте: git clone server.name.tld:repo/git/project.git project;
  • копируем содержимое исходников в директорию project и выполняем
    git add .
    git commit -a -m "inital release"
    git push origin master
    

начиная с клиента

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


синхронизация всех веток в bare репозиториях

git clone --bare url local.git
cd local.git
git config --add remote.origin.fetch '+refs/*:refs/*' 
git fetch


pull all branches to local

git branch -a | 
 sed -n \"/\\/HEAD /d; /\\/master$/d; /remotes/p;\" | 
 xargs -L1 git checkout -t"


pull single branch to local

git checkout -t remotes/origin/<branch_name>


drop last n commits

git reset --hard HEAD~n


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


edit, reword, squash, fixup, drop last n commits

git rebase -i HEAD~n


grep commit contents

git log -p --all -G clean_empty_state


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 (prefered):
    • 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