Last active
January 21, 2022 07:22
-
-
Save PolarbearDK/3c131587979fbcdc829899401ad8c1b6 to your computer and use it in GitHub Desktop.
Common patterns with git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Fetch and update master branch | |
$ git fetch | |
$ git checkout master | |
$ git pull | |
or | |
$ git checkout -B master origin/master | |
-- Create branch and checkout (usually from from develop or master) | |
git checkout -b FOO-XXX_SomeMessage | |
Remember to always create branch "folders" using lower case like branch feature/story/Some-story. | |
If you mix upper/lower in different branches, then git will blow spectacularly on Windows. | |
-- Rename current branch | |
git branch -m FOO-XXX_SomeOtherMessage | |
-- Delete unwanted branch | |
git branch -d FOO-XXX_SomeMessage | |
(-d cannot delete unmerged branches. Use -D to delete it even if it is not merged) | |
-- Delete remote branch | |
git push origin --delete feature/foo_branch | |
-- List status for current branch | |
git status | |
-- Hotfix/Feature flow (same flow for features on develop, hotfix on master) | |
Fetch and update main branch | |
$ git checkout -b FOO-XXX_description | |
<add one or more commits into branch> | |
$ git fetch | |
$ git rebase origin/master | |
$ git checkout -B master origin/master | |
$ git merge --no-ff FOO-XXX_description | |
$ git push origin master | |
Note! Never merge branch using fast-forward, as it hides information about when branch was merged. | |
-- Rebase | |
$ git fetch | |
$ git checkout FOO-XXX_SomeMessage | |
$ git rebase origin/develop | |
Ved merge errors run: | |
$ git mergetool | |
$ git rebase --continue | |
$ git push --force-with-lease | |
-- Cherry pick | |
git checkout develop | |
git cherry-pick 0393eeca805834fd60d93d0cb8882f54fe2d479e | |
git mergetool | |
git status | |
git commit | |
-- Splice tree to new place. | |
-- <fromCommitExcluding> is the commit just below where the tree is cut | |
-- <toCommit> is often current branch. | |
$ git rebase --onto <newplace> <fromCommitExcluding> <toCommit> | |
-- Cleanup remote branches | |
$ git remote prune origin | |
-- Check if feature branch is merged into antoher branch | |
git lol FOO-XXX_SomeMessage ^develop | |
(use -p at end do display diff patches) | |
(use --stat to list change files) | |
-- Cleanup folders for files not under source control | |
git clean -xdf | |
-- List commit by commit number | |
git lol "hexcommit" | |
-- Show reflog | |
git reflog | |
-- Check local git repository status (sort of...) | |
git count-objects -v -H | |
-- Cleanup and compress local git repository | |
git gc --aggressive --prune=now | |
-- Ignore changes to local file | |
git update-index --assume-unchanged ./Path/To/File/PublishToLocalIS.pubxml.user | |
Undo: git update-index --no-assume-unchanged ./Path/To/File/PublishToLocalIS.pubxml.user | |
--- Tags | |
- Create tag | |
git tag 1.0.0 | |
git push origin 1.0.0 | |
- Create tag at specific hash | |
git tag 1.0.0 f3ad47d4e6201b446b63bb29a8205a1f236fe940 | |
- Delete tag (locally) | |
git tag -d release/1.0.0 | |
$ git push origin :release/1.0.0 | |
- Push create + delete | |
$ git push origin 1.0.0 :release/1.0.0 | |
-- SSH agent | |
eval `ssh-agent` | |
ssh-add | |
-- Prevent mergecommit message dialog --- | |
GIT_MERGE_AUTOEDIT=no | |
export GIT_MERGE_AUTOEDIT | |
--- List branches | |
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%an %ci %cr" $branch | head -n 1` \\t$branch; done | sort -r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment