development:git
Differences
This shows you the differences between two versions of the page.
| development:git [2025/10/30] – created hayati | development:git [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ~~NOTRANS~~ | ||
| + | |||
| + | {{indexmenu_n> | ||
| + | |||
| + | ====== Git ====== | ||
| + | |||
| + | This is my git cheat-sheet, | ||
| + | |||
| + | ===== cloning ===== | ||
| + | |||
| + | < | ||
| + | git clone git@github.com:/< | ||
| + | git clone https:// | ||
| + | |||
| + | # only specific branch | ||
| + | git clone --branch < | ||
| + | |||
| + | # clone including submodules | ||
| + | git clone --recursive git@github.com:/< | ||
| + | git clone --recursive https:// | ||
| + | </ | ||
| + | |||
| + | ==== shallow option ==== | ||
| + | |||
| + | saves local space - by just getting last (few) commits | ||
| + | |||
| + | < | ||
| + | git clone --depth 1 ... | ||
| + | git clone --branch < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== work with branches ===== | ||
| + | |||
| + | ==== list existing branches ==== | ||
| + | |||
| + | < | ||
| + | git branch -l # local only | ||
| + | git branch -a # all - including remotes | ||
| + | </ | ||
| + | |||
| + | ==== create branch ==== | ||
| + | |||
| + | create local branch and switch to that one | ||
| + | < | ||
| + | git checkout -b < | ||
| + | </ | ||
| + | |||
| + | create private dev branch - might require configuration of git server | ||
| + | < | ||
| + | git push origin HEAD: | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== work on local branch ==== | ||
| + | |||
| + | * edit files locally | ||
| + | * '' | ||
| + | * NO '' | ||
| + | |||
| + | |||
| + | ==== get updates from remote ==== | ||
| + | |||
| + | < | ||
| + | git pull --rebase | ||
| + | |||
| + | git fetch origin master | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== overwrite/ | ||
| + | |||
| + | < | ||
| + | git push --force | ||
| + | git push --force-with-lease | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== delete branch ==== | ||
| + | |||
| + | < | ||
| + | git branch -d < | ||
| + | git push origin --delete < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== rename local branch ==== | ||
| + | |||
| + | < | ||
| + | git branch -m < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== push to different name ==== | ||
| + | |||
| + | < | ||
| + | git push origin < | ||
| + | git push origin HEAD:< | ||
| + | git push -f origin HEAD: | ||
| + | </ | ||
| + | |||
| + | see https:// | ||
| + | |||
| + | push current/ | ||
| + | |||
| + | < | ||
| + | git push -u origin < | ||
| + | |||
| + | git push --force-with-lease -u origin < | ||
| + | gpf -u origin < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== rebase (update/ | ||
| + | |||
| + | commits, which didn't exist when creating of the feature_branch, | ||
| + | are inserted (put/ | ||
| + | then, the patches(commits) of the feature_branche are applied.\\ | ||
| + | |||
| + | usually, the feature branch was created from a master.\\ | ||
| + | master got additions/ | ||
| + | now, we want to ' | ||
| + | |||
| + | |||
| + | have master updated before | ||
| + | |||
| + | < | ||
| + | git checkout < | ||
| + | git rebase master | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== squash apply commits of branch onto master ==== | ||
| + | |||
| + | < | ||
| + | git checkout master | ||
| + | |||
| + | git merge < | ||
| + | git merge --squash < | ||
| + | |||
| + | git push | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== submodules ===== | ||
| + | |||
| + | more actions with submodules, see https:// | ||
| + | |||
| + | ==== retrieve submodules automatically when cloning ==== | ||
| + | |||
| + | < | ||
| + | git clone --recursive git@github.com:/< | ||
| + | git clone --recursive https:// | ||
| + | </ | ||
| + | |||
| + | ==== retrieve submodules later ==== | ||
| + | |||
| + | < | ||
| + | git submodule init | ||
| + | git submodule update --recursive | ||
| + | |||
| + | # or in one step | ||
| + | git submodule update --init | ||
| + | git submodule update --init --recursive | ||
| + | </ | ||
| + | |||
| + | ==== add submodule ==== | ||
| + | |||
| + | a submodule can be added any time and everywhere within an existing repository. it retrieves the new repository as with '' | ||
| + | |||
| + | < | ||
| + | git submodule add https:// | ||
| + | |||
| + | # e.g. | ||
| + | git submodule add https:// | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== stashing ===== | ||
| + | |||
| + | < | ||
| + | git stash save "< | ||
| + | git stash list # alias: sl | ||
| + | git stash apply stash@{< | ||
| + | git stash pop stash@{< | ||
| + | git stash drop stash@{< | ||
| + | git stash show -p stash@{< | ||
| + | </ | ||
| + | |||
| + | backup stash contents into a branch | ||
| + | < | ||
| + | git branch < | ||
| + | git push origin < | ||
| + | </ | ||
| + | |||
| + | ===== push except last commit(s) ===== | ||
| + | |||
| + | https:// | ||
| + | |||
| + | < | ||
| + | # git push < | ||
| + | git push origin 555555: | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== cherry picking ===== | ||
| + | |||
| + | http:// | ||
| + | < | ||
| + | git checkout master | ||
| + | git log # remember/ | ||
| + | git checkout < | ||
| + | |||
| + | git cherry-pick -x < | ||
| + | git cherry-pick < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== tagging ===== | ||
| + | |||
| + | see https:// | ||
| + | |||
| + | annotated tags are pushed, when using git push explicitly with option '' | ||
| + | < | ||
| + | git push --follow-tags | ||
| + | </ | ||
| + | |||
| + | or when having previously configured | ||
| + | < | ||
| + | git config --global push.followTags true | ||
| + | </ | ||
| + | |||
| + | Above option allows pushing a commit together with it's tag in one step - without additional '' | ||
| + | |||
| + | |||
| + | < | ||
| + | git tag -a -m "< | ||
| + | git tag -a < | ||
| + | git tag -a < | ||
| + | # git log --pretty=oneline | ||
| + | git push origin < | ||
| + | |||
| + | git tag -d < | ||
| + | git push origin : | ||
| + | git push origin :< | ||
| + | git push --delete origin < | ||
| + | |||
| + | git tag # lists tags | ||
| + | git show < | ||
| + | |||
| + | git checkout -b < | ||
| + | </ | ||
| + | |||
| + | ==== move tag ==== | ||
| + | |||
| + | < | ||
| + | git tag -d < | ||
| + | git tag -a < | ||
| + | git push -f origin < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== resolving conflicts ===== | ||
| + | |||
| + | recovering from disasterous git rebase mistake\\ | ||
| + | see https:// | ||
| + | |||
| + | < | ||
| + | git fetch --all | ||
| + | git reset --hard origin/ | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== work with remotes ===== | ||
| + | |||
| + | ==== show all remotes ==== | ||
| + | |||
| + | < | ||
| + | git remote -v | ||
| + | </ | ||
| + | |||
| + | example output | ||
| + | |||
| + | < | ||
| + | origin | ||
| + | origin | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== add a remote ==== | ||
| + | |||
| + | < | ||
| + | git remote add < | ||
| + | |||
| + | # e.g. git remote add upstream https:// | ||
| + | |||
| + | git fetch < | ||
| + | git branch -a | ||
| + | </ | ||
| + | |||
| + | ==== remove/ | ||
| + | |||
| + | < | ||
| + | git remote rm < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== create branch from a remote ==== | ||
| + | |||
| + | < | ||
| + | git checkout -b < | ||
| + | </ | ||
| + | |||
| + | ==== get log of a remote branch ==== | ||
| + | |||
| + | < | ||
| + | git log < | ||
| + | </ | ||
| + | |||
| + | ==== pull / rebase onto remote ==== | ||
| + | |||
| + | < | ||
| + | # git pull [--rebase] {repo(remote)} {remotebranchname}: | ||
| + | |||
| + | git pull --rebase < | ||
| + | |||
| + | # e.g. git pull --rebase upstream development | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== change remote' | ||
| + | |||
| + | < | ||
| + | git remote set-url < | ||
| + | |||
| + | # e.g. git remote set-url origin git@github.com: | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== push specific commit to remote ==== | ||
| + | |||
| + | < | ||
| + | git push < | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== misc operations ===== | ||
| + | |||
| + | ==== set upstream ==== | ||
| + | |||
| + | set default push target to upstream gloabally - needed just once, that local branch name needn' | ||
| + | |||
| + | < | ||
| + | git config --global push.default upstream | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== determine top level directory ==== | ||
| + | |||
| + | < | ||
| + | git rev-parse --show-toplevel | ||
| + | </ | ||
| + | |||
| + | see https:// | ||
| + | |||
| + | |||
| + | ==== hide subdirectory and its contents in git gui ==== | ||
| + | |||
| + | create '' | ||
| + | |||
| + | < | ||
| + | echo " | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== loose objects warning with git gui ==== | ||
| + | |||
| + | git-gui reports it has N loose objects each time it is run; then try | ||
| + | |||
| + | < | ||
| + | git gc --aggressive | ||
| + | </ | ||
| + | |||
| + | or, if the problem remains | ||
| + | |||
| + | < | ||
| + | git config --global gui.gcwarning false | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== show specific commit ==== | ||
| + | |||
| + | < | ||
| + | git show < | ||
| + | </ | ||
| + | |||
| + | see https:// | ||
| + | |||
| + | |||
| + | ===== Git Tools ===== | ||
| + | |||
| + | * git | ||
| + | * Text/ | ||
| + | * git '' | ||
| + | * tig '' | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * GUI | ||
| + | * git-gui, gitk '' | ||
| + | * gitg for nice browsing '' | ||
| + | * GitHub | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * Tool Overview | ||
| + | * https:// | ||
| + | * giggle, git-cola and qgit look interesting | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | * Setting up and using Meld as your git difftool and mergetool | ||
| + | * https:// | ||
| + | |||
| + | |||
