Git Notes
Shell#
Show the Time and Git Branch on the Shell Prompt#
I set up my Bash prompt to show the current time, and if inside a Git repo path, to also show the name of the checked-out branch. The following goes at the end of ~/.bashrc, to override any previously set PS1 (the environment variable for the shell prompt's format string):
1 2 3 4 5 6 | |
The shell prompt should look something like this now:
1 2 3 | |
Convenient Single-Letter Aliases#
I keep a few short shell aliases in ~/.bashrc for the Git commands I use the most day to day. All of them are for read-only actions though, muscle memory can be dangerous when you're tired...
1 2 3 4 5 6 | |
Colored Text in the Terminal#
Add to ~/.gitconfig:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Repo Management#
Push to Multiple URLs#
Git remotes can be configured to push to multiple URLs, which is great for having backups and keeping things distributed. You can add extra addresses with git remote set-url --add --push origin git@host2:project.git or edit the project's .git/config directly:
1 2 3 4 5 | |
Remotes should look something like this now:
1 2 3 4 5 | |
Merge Two Separate Git Repos#
I create a new Git repo for every game jam project, but afterwards I merge it to a single archive repo that has all my past jam entries, preserving the original commit history of each.
Starting with the new game's repo at ~/newgamerepo, I first move everything from the project root to a subfolder:
1 2 3 4 | |
Then I merge the game repo to the archive repo at ~/gamejams:
1 2 3 4 | |
The new game lands at ~/gamejams/newgame/. The --allow-unrelated-histories flag lets us merge Git histories with no common ancestors, in other words distinct repos.
Filter Changes of a Particular File by Keywords#
This lists commits that added or removed occurences of MyKeyword in a file:
1 | |
Repo Upkeep#
Remove All Files Not Part of the Repo#
1 | |
-d: remove directories too, not just files-f: allows removing without an explicit permission set in.git/config-x: remove files even if they match.gitignorerules, like build output files
Fix Issues Identified by git fsck#
One day I learned about this Git command and tried it out in one of my repos:
1 2 3 4 5 6 | |
The following fixed everything, beware losing any uncommitted changes:
1 2 3 4 | |