Obsah

GIT

Založení repo

git init [slozka]
git remote add origin https://example.com/user/test.git
git clone https://example.com/user/test.git [lokalni_slozka]
git config [--global] user.name "First Last name"
git config [--global] user.email "first.last@example.com"

Nastavení

git config [--global] credential.helper "cache"

Commit

git status [cesta]
git add [cesta]
git commit [-m "MSG"]
git push [name]
git pull [name]
git config --system core.editor <editor>

Změny

git commit --amend
git push --force-with-lease [repository] [branch]

Vracení změn

Reset

git reset [cesta]
git reset --hard
git reset <rezim> [revize]

Checkout

git checkout [revize] [cesta]
git checkout [vetev]
git checkout [vetev] [cesta]

Revert

git revert [commit]

Odkládání změn

git stash [save "stash_name"]
git stash list
git stash show [stash_name]
git stash apply [stash_name]
git stash pop [stash_name]
git stash drop [stash_name]
git stash clear 

Vyzvedávání změn

Fetch

git fetch [<origin> [master]]
git fetch --prune

Merge

git merge origin/master
git log --oneline master..origin/master

Větve

Informace

git branch [--all|-a]
git branch -vv

Úpravy

git branch new_feature
git checkout -b new_feature
git checkout master
git branch -d new_feature
git fetch --prune
git branch -m awesome_feature

Tagy

Informace

git tag
git tag --list "v1*"
git tag --points-at b7ef32
git show v1.0

Úpravy

git tag -a v2.0-beta -m "Releasing v2 beta"
git tag -a v2.0-beta -m "Releasing v2 beta" dd7216
git tag -a v1.0 --force
git tag -d v1.0

Prohlížení commitů

git log
git log -n2  # maximálně dva commity
git log --oneline # jeden řádek na commit
git log --all

Prohlížení rozdílů

git diff [path]
git diff [<commit> [path]]
git diff ---cached [<commit> [path]]
git diff <commit> <commit> <path>
git log --oneline master..origin/master
git diff master..origin/master
git difftool --dir-diff origin/moje-branch

Externals

Submodule

git clone <URL>
git submodule init   // inicializuje adresář subprojektu
git submodule update // nastaví obsah adresáře subprojektu na referenci
git pull
git submodule update --remote 
git checkout <BRANCH>
git pull
git submodule deinit <path/to/module>
git rm <path/to/module>
rm -rf .git/modules/<MODULE>  // zruší zbytek lokalních referencí, jinak může dělat v budoucnu problémy
git submodule add [-b <BRANCH>] [URL] [DIR]
git config -f .gitmodules submodule.<path>.branch <branch>
git submodule update --remote
cd [SUBMODULE]
git checkout [NEWBRANCH]

Workflow

GitLab

Řešení konfliktů při merge

VER_FROM=<version_from>
VER_TO=<version_to>

git fetch origin
git checkout ${VER_FROM}
git pull
git branch -D merge-${VER_FROM}-to-${VER_TO}
git checkout -b merge-${VER_FROM}-to-${VER_TO} origin/${VER_TO}
git merge --no-ff ${VER_FROM}
git mergetool

git commit -m "Resolve conflicts"
git push origin merge-${VER_FROM}-to-${VER_TO}

Git HTTPS server

Webdav

error: Cannot access URL https://XXXXXX, return code 22
fatal: git-http-push failed
vim .git/config
[remote "origin"]
    url = https://USER@XXXXX/YYYY.git
git clone https://XXX/YYYY.git -c http.sslVerify=false
[http "https://XXXXXX"]
        sslverify = false

Odkazy