Show the current Git branch on your Bash prompt
Append this to your ~/.bashrc
:
export PS1='\[\033[01;32m\]\h\[\033[01;34m\] \w\[\033[31m\]$(__git_ps1 "(%s)") \[\033[01;34m\]$\[\033[00m\] '
Reload the changes by saying
source ~/.bashrc
For some customized prompts that also show the current Git prompt, see the examples section at the bottom of our bash prompt customizing card.
Related cards:
Git: How to configure git to push only your current branch
You can change which branches will be pushed when saying git push
. Our recommendation is to set it to current
.
From the git-config
documentation:
push.default
: ^
Defines the action ...
Customize your Bash prompt
The shell variable PS1
holds your bash prompt. You might want to change it to serve your needs best. Here is how to:
General
- non-printing escape sequences in your prompt have to be inclosed in
\[\e[
and\]
so your shell can...
Git: removing feature branches on merge
When working with feature branches, stale branches pile up over time. It's best to remove them right after merge, locally and on the remote, but it is a little t...
Git: Show current branch name only
While git branch
will show you all branches and highlight the current one with an asterisk, it can be too cumbersome when working with lots of branches.
To show only the branch you are currently on, use:
git rev-parse --abbrev-ref HEAD
Git: How to rebase your feature branch from one branch to another
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"
Let's say my-feature-branch
...
Configuring Git with .gitconfig
Basic configuration
Please 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 "bra...
Git shortcut to rebase onto another branch
Inspired by recent "git shortcut" cards I figured it would be nice to have one of these for rebasing a few commits onto another branch. The usual notation is prone to of-by-one errors as you have to either specify the commit before the ones you ...
Git: In an (interactive) rebase, find out which commit you are currently working on (until version < 1.7.9.5)
When you are using git rebase
and are currently editing a commit (due to a conflict, for example), you may want to know the current commit. [1]\
Luckily, there is lots of useful stuff in the .git
directory.
Commit hash that you are curre...
Lightning Talk: Coverage based Test Case Prioritization in Ruby on Rails
For my computer science bachelor's thesis I programmed and evaluated a CLI Test Case Prioritization (TCP) tool for makandra. It has been written as a Ruby Gem and was tested and evaluated against one Ruby on Rails project....
Git: rebase dependent feature branch after squash
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 commits of branch one
have changed after you branched two
from...