How do I “git blame” a deleted line?

If you know the contents of the line, this is an ideal use case for: git log -S <string> path/to/file which shows you commits which introduce or remove an instance of that string. There’s also the -G<regex> which does the same thing with regular expressions! See man git-log and search for the -G and -S … Read more

Push commits to another branch

That will almost work. When pushing to a non-default branch, you need to specify the source ref and the target ref: git push origin branch1:branch2 Or git push <remote> <branch with new changes>:<branch you are pushing to>

Git add and commit in one command

You can use git aliases, e.g. git config –global alias.add-commit ‘!git add -A && git commit’ and use it with git add-commit -m ‘My commit message’ EDIT: Reverted back to ticks (‘), as otherwise it will fail for shell expansion on Linux. On Windows, one should use double-quotes (“) instead (pointed out in the comments, … Read more

What is “origin” in Git?

origin is an alias on your system for a particular remote repository. It’s not actually a property of that repository. By doing git push origin branchname you’re saying to push to the origin repository. There’s no requirement to name the remote repository origin: in fact the same repository could have a different alias for another … Read more

How to rebase local branch onto remote master

First fetch the new master from the upstream repository, then rebase your work branch on that: git fetch origin # Updates origin/master git rebase origin/master # Rebases current branch onto origin/master Update: Please see Paul Draper’s answer for a more concise way to do the same – recent Git versions provide a simpler way to … Read more