...pushed when saying git push. Our recommendation is to set it to current. From the git-config documentation: push.default Defines the action git push should take if no refspec is...

...check your setting, do the following. By default, it will return matching (see above). $ git config --global push.default matching So to change that to push only current branches, just go...

makandra dev

git checkout is the swiss army of git commands. If you prefer a semantically more meaningful command for restoring tasks, use git restore instead. With this command you...

Info For this use case you can also use git checkout. Sources Git - git-restore Documentation Also see Git commands to discard changes Git restore vs reset

You have uncommited changes (you can always check by using git status), which you want to discard. Context Now there are several options to discard these depending on...

Staged and unstaged changes Revert all changes to modified files (tracked and untracked) git reset --hard If you might want to use the changes later on git stash will...

...you need to remember it, and perform the few steps manually each time. Enter Git hooks. The folks at Liquid Light have built a little post-merge hook that will...

...delete a feature branch on confirmation. Quick aside: Git hooks location Git hooks are normally stored in the current repository, at .git/hooks/. They are not checked in and will not...

stackoverflow.com

This card will show you how to use git rebase --onto without confusion. Use case: You've got two feature branches (one and two), where two depends on one. Now...

...of branch two onto branch one. The easiest way for me to correctly use git rebase --onto is to count the number of additional commits of branch two and use...

makandracards.com

...you're hunting down a regression (or just a bug) and want to use git bisect to find out when it was introduced? Smart kid. If you have a shell...

...ready to reveal if your current state is good or bad, you can have git do most of the work for you. Using git bisect run you can tell git...

This is a guide on how to effectively use Git when working on a feature branch. It is designed to get out of your way as much as possible while...

...has never been "partially" merged into master. You want to start a feature branch git checkout master git checkout -b my-feature-branch git push -u origin my-feature-branch...

The Git stash does not work like a one-slot clipboard and you might shoot yourself in the foot if you pretend otherwise. In particular git stash apply does not...

...the stash. That means you will probably apply the wrong stash when you do git stash apply after a future stashing. To keep your stash clean, you can use

...CI run, simply add [ci skip] or [skip ci] to your commit message. Example: git commit -m "wip authentication [ci skip]" Git push options (GitLab) In addition to that, GitLab...

...CI supports Git push options. Instead of changing your commit message, specify the ci.skip option when pushing. Example: git commit -m "wip authentication" git push -o ci.skip Documentation GitHub Actions...

git --fixup is very handy to amend a change to a previous commit. You can then autosquash your commits with git rebase -i --autosquash and git will do the magic...

...for you and bring them in the right order. However, as git --fixup wants a ref to another commit, it is quite annoying to use since you always have to...

In a nutshell: Use git rebase --onto target-branch source-commit target-branch means "branch you want to be based on" source-commit means "commit before your first feature commit...

...master and we want it to be based on production. Consider this history: %%{init: { 'gitGraph': {'showCommitLabel': true, 'mainBranchName': 'production'}} }%% gitGraph commit id: "1" commit id: "2" branch master

...large rubocop commits or big renamings in your project. You can add and commit a .git-blame-ignore-revs file in your project to track a list of commits that...

...Use git blame with the --ignore-revs-file option and ignore the SHAs specified in .git-blame-ignore-revs. git blame --ignore-revs-file .git-blame-ignore-revs

makandra dev
stackoverflow.com

git rebase -i -> mark your commit with edit git reset HEAD~ (remove the marked commit, but keep its changes) Make several commits (optionally setting the previous author manually...

...git rebase --continue Detailed instructions Basically, you will review the last n commits and stop at the splittable commit. Then you'll undo that commit and put its changes into...

First find the reference for the entry you want through looking at the stash: $ git stash list stash@{0}: WIP on feature/foo stash@{1}: WIP on feature/bar stash@{2}: WIP...

Now you can simply use that reference, but curly braces must be escaped: git stash pop stash@\{1\} or quoted: git stash apply "stash@{1}" Quick reminder to not...

In interactive commands, Git allows the user to provide one-letter input with a single key without hitting enter (docs). # Enabled this feature globally git config --global interactive.singlekey true

...enable this feature locally for a single repository git config interactive.singlekey true This allows you to hit "y" instead of "y + ENTER" to move to the next hunk.

You can use git worktree to manage multiple working trees attached to the same repository. But why should I use git worktree? You can use more than one working tree...

...done, you can remove the working tree with git worktree remove . For more details see git-worktree. Warning Worktrees share the git directory (a new worktree points to the .git...

...but not all commits from main to production. This can be done with a git cherry-pick. However, this may lead to considerable pain later, since git does not understand...

So the full workflow to move the AWESOME_COMMIT_SHA1 to production is: git checkout production git cherry-pick AWESOME_COMMIT_SHA1 git checkout main git merge production

The git doc states on the difference of these two commands: git-restore[1] is about restoring files in the working tree from either the index or another commit. This...

...The command can also be used to restore files in the index from another commit. git-reset[1] is about updating your branch, moving the tip in order to add...

Using git checkout - you can switch back to the branch you previously worked on. (master) $ git checkout foobar Switched to branch 'foobar' (foobar) $ git checkout - Switched to branch 'master'

...This also works with other commands like git merge: (master) $ git checkout foobar Switched to branch 'foobar' (foobar) $ git merge - Merged branch 'master...

...want to add from the working directory to the index. Step by step: Use git reset --soft HEAD~n (or git reset --soft ) Then remove file selectively from the index...

...by using git reset -- . 2.1 If you need to add specific changes selectively again you can use git add -p Then only commit the staged files Afterwards add the unstaged...

Git commits should be very deliberate, and only contain changes that you really want to be in there. In order to reduce the chance to accidentally commit something you didn...

...review your changes before committing. My preferred way of doing this is (only using git) git add -N . # Add all paths, but not their contents git add -p

tekin.co.uk

Git diffs show the surrounding contexts for diff hunks. It does so by applying regular expressions to find the beginning of a context. When it comes to Ruby, however, it...

- assigns: { tickets: tickets } + assigns: { tickets: tickets, event_name: event_name } ) end end When Git is told how to recognize a Ruby file, it will correctly display the expected context...

chris.beams.io

Tip As an alternative, use a commit message that refers to a GitHub issue (fixes #321) or story ID from your issue tricker. Examples for 5 Use the...

makandra dev

...keep this config simple. It should be a starting point for new developers learning Git. [user] name = Your Name email = your.name@domain.com [branch] sort = -committerdate [color] ui = auto [color "branch"]

...delta, a fancy diff tool with syntax highlighting and inline change highlighting. Installation Download a git-delta_*_amd64.deb file from the releases page. On Ubuntu 20.04, I had to use...