Git allows you to set push options when pushing a branch to the remote. You can use this to build an alias that automatically pushes a branch and creates a...
...alias] section: mr = push origin HEAD -o merge_request.create -o merge_request.draft Now you can do git mr and a draft merge request will be created. Target branch is your project's...
Git commands like diff use the less binary for their output representation. I often find myself searching for strings like todo, then switching to the case-insensitive mode (-i) and...
...re-doing my search. Today I figured out that you can configure git to show case insensitive diffs every time: git config --global core.pager 'less -i...
...changing this, so think before you do it. If you do, you can tell git to stash automatically before pulling: git config --global rebase.autoStash true Now on pull, git will...
...Note that applying your changes may lead to unresolvable conflicts! Further see a common git config with this configuration enabled...
In order to have more human readable git branches, do git pull --rebase To always pull like this, write these lines to your ~/.gitconfig: [pull] rebase = true
git config --global pull.rebase true Note that this will break if you pull from other upstream branches like git pull origin other-branch If you keep rebasing by default...
Saying git diff only shows unstaged changes relative to the index (or HEAD if the index is empty, alternatively any hash or branch you supplied) but leaves out files you...
...already staged for the next commit. To diff your added changes with HEAD, say: git diff --cached Effectively, this gives you the changes you will commit when you run git...
Delete feature branches Find already-merged branches by running # On branch master git branch --merged You may safely delete each of the listed branches, because they point to...
...commits that are contained in the history of your current branch (i.e. master). git branch -d my/feature-branch # Delete feature branch locally git push origin :my/feature-branch # Push *nothing* to the feature...
Git has two kind of tags: annotated lightweight Annotated tags are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have...
...verified with GNU Privacy Guard (GPG) The following command will create a (lightweight) tag: git tag v0.1 An annotated tag is created by: git tag -a v0.1 -m "a special...
...with the following content. --- BUNDLE_PATH: "vendor/" BUNDLE_DISABLE_SHARED_GEMS: "true" Change your .gitignore. # Make sure to check in .bundle # /.bundle/ /vendor/ruby Run bundle package and commit the changes...
If you want to see the git history of a project file, that doesn't exist anymore, the normal git log won't work. You have to add certain flags...
...to make it work: git log --all --full-history...
git commit -m "Rename foo to bar" git log bar commit adc8e6a05b65355359c4e4618d6af0ed8f8b7f14 (HEAD -> git-follow) Author: Michael Leimstaedtner <makmic@makandra.de> Date: Wed May...
...Rename foo to bar git log --follow bar commit adc8e6a05b65355359c4e4618d6af0ed8f8b7f14 (HEAD -> git-follow) Author: Michael Leimstaedtner <makmic@makandra.de> Date: Wed May 12 08:49:37 2021 +0200 Rename foo to bar...
...changes matching a given regular expression for a single commit. Example Consider the following git diff output. diff --git a/file1.rb b/file1.rb index 806ca88..36d536b 100644 --- a/file1.rb +++ b/file1.rb...
-# It will be removed. class File1 - def foo + def bar # ... end end diff --git a/file2.rb b/file2.rb index 550e1c6..600f4e3 100644 --- a/file2.rb +++ b/file2.rb @@ -1,6 +1,5 @@
It's like a GUI for the famous git add [-p]. Select files with the up/down-keys and hit u for staging/unstaging the whole file Enter for showing the diff of...
...at the commit details show you the changes, etc). Now, when you do a git log you see them, but when you say git log that.file these commits don't...
...is that the file got deleted deleted/re-added/renamed (any or all of those). Instead of ... git log master -- some.file ... you need to say: git log --follow master -- some.file Then your commits...
...and fix trailing whitespace in your commits. Bypass # it with the --no-verify option to git-commit. # detect platform platform="win" uname_result=`uname` if [[ "$uname_result" == "Linux" ]]; then
...Removed trailing whitespace in \033[31m$file\033[0m:$line_number" done echo # credits: # https://github.com/philz/snippets/blob/master/pre-commit-remove-trailing-whitespace.sh # https://github.com/imoldman/config/blob/master/pre-commit.git.sh # If there still are whitespace errors, print the offending file...
This is called "cherry-picking". git cherry-pick commit-sha1 Note that since branches are nothing but commit pointers, cherry-picking the latest commit of a branch is as simple...
git cherry-pick my-feature-branch Be aware that cherry-picking will make a copy of the picked commit, with its own hash. If you merge the branch later...
...find a version containing the regular expression foo in the history of any branch: git grep foo $(git rev-list --all) You may also limit the search to a file...
...extension, e.g. Ruby files (.rb) like this: git grep foo $(git rev-list --all) -- *.rb
Resolve @{-1} to actual branch name. (Happens when merging "-".)
tldr; Use git diff -M or git diff --find-renames when you've moved a few files around. Usage $ git diff --help Options: -M[ ], --find-renames[= ] Detect renames. If n...
...i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the...
I am using git at several places: at work, at university, and at home. I want an own git user/email for each of those places, but I don't want...
...to care setting the values each time I create or clone a new repository. Git allows for setting user/email per repository, globally and system-wide, but I need a fourth...
When doing a git blame, git will blame the person who added or removed white space in a line (e.g. by indenting), not the person who originally wrote the code...
...Say git blame -w to ignore such white-space changes. You want this. \ Note that you can also use it when diffing: git diff -w. Example Consider this method, created...
Using git rebase can be painful but luckily you can resort to cheating with git reset and committing anew. Now what if you wanted to rebase commits of other people...
...freshly staged changes that are ready to be committed, just use the --author switch: git commit -m "Hello Universe" --author="Philip J Fry <someone@example.com>" If you already committed, just change...
...proxy misconfiguration, you might have to deploy to a server that cannot access the git repository. Solution 1: HTTP Proxy (this is the preferred fix) SSH can be tunneled over...
...an HTTP Proxy. For example, when the repo is on github, use this: Install socat Add a ~/.ssh/config on the target server(s) with permission 0600 and this content:
...or any mess you need to clean up later. While you can just use git diff or git diff --cached (to diff staged changes), you can also have Git include...
...the changes as a comment below the commit message: git commit -v That will open up the usual commit "file" in your preferred text editor, but it will include a...
When using git diff, you might encounter weird characters where umlauts (or any other UTF-8) characters should be. It looks like this: R ckg ngig # should be "Rückgängig"
...not Git is to blame but the less command that Git uses to page your diff output. You need to tell less to use UTF-8 (otherwise it tries to...