Block a git branch from being pushed

Here’s how the pre-push hook approach works, with a branch called dontpushthis. Create this file as .git/hooks/pre-push: #!/usr/bin/bash if [[ `grep ‘dontpushthis’` ]]; then echo “You really don’t want to push this branch. Aborting.” exit 1 fi This works because the list of refs being pushed is passed on standard input. So this will also … Read more

How to see commits that were merged in to a merge commit?

git log abc123^..abc123 shows the commits that got merged into merge-commit abc123. Create a git alias log-merge for easy reuse: $ git config –global alias.log-merge \ ‘!f() { git log –stat “$1^..$1”; }; f’ $ git log-merge abc123 For a one-line version: $ git config –global alias.log-merge-short \ ‘!f() { git log –pretty=oneline “$1^..$1”; }; … Read more

Switch branch names in git

In addition to the other comments, you may find the -m (move) switch to git-branch helpful. You could rename your old master to something else, then rename your new branch to master: git branch -m master crap_work git branch -m previous_master master

View differences of branches with meld?

Short & sweet: git config –global diff.tool meld This configures Git to use meld as the diff tool. (You don’t need to specify the command line arguments, support for meld is built into Git.) Then, if you want a graphical diff instead of a textual one, you simply invoke git difftool instead of git diff … Read more

Mercurial: Can I rename a branch?

Update to the stiging branch and create a new branch off of it. Then close the old branch. In summary: hg update stiging hg branch staging hg commit -m”Changing stiging branch to staging.” hg update stiging hg commit –close-branch -m”This was a typo; use staging instead.” hg push –new-branch

Git: Merge a Remote branch locally

You can reference those remote tracking branches ~(listed with git branch -r) with the name of their remote. You need to fetch the remote branch: git fetch origin aRemoteBranch If you want to merge one of those remote branches on your local branch: git checkout aLocalBranch git merge origin/aRemoteBranch Note 1: For a large repo … Read more

Renaming a branch in GitHub

As mentioned, delete the old one on GitHub and re-push, though the commands used are a bit more verbose than necessary: git push origin :name_of_the_old_branch_on_github git push origin new_name_of_the_branch_that_is_local Dissecting the commands a bit, the git push command is essentially: git push <remote> <local_branch>:<remote_branch> So doing a push with no local_branch specified essentially means “take … Read more

tech