University of Oregon

An improved PS1 for Git in Bash

Last year I updated my bash prompt (PS1) to include the active git branch name.
A few months ago I added to the the active repository name.
So here’s an example of my PS1 when I’m in a git tracked directory on the master branch:

vid@server mydirectory (origin [master])$ 

And here it is when I have other remote repositories for the same project (bronze and heuristics);

vid@server mydirectory (bronze | heuristics | origin [master])$ 

And now once more when I’m on a branch (devel) that doesn’t exist on the available remotes:

vid@server mydirectory (bronze | origin [devel])$ 

That’s achieved with these functions: parse_git_branch and show-git-current-remotes-short.
(more…)

Auto populate from History via up and down arrow keys

I posted a highlight of some bash code that Jason H shared last year in my git_bash_files repo on bitbucket. Auto_populate_from_History_via_up_and_down_arrow_keys

Branching with Git – Follow up on keeping remote and local sync’d

I saw a follow up comment on the article that I built my git-create-branch function on and so I updated the code. *Thanks goes to Olivier Clavel.
Here’s the update: http://www.zorched.net/2008/04/14/start-a-new-branch-on-your-remote-git-repository/comment-page-2/#comment-18065
Here’s my original post: http://pages.uoregon.edu/vid/2012/06/05/branching-with-git-keeping-remote-and-local-syncd/

In addition to updating the git functions used I improved the function itself by adding more feedback to the user.
Here are the new functions: git-create-branch() and git-delete-branch();
(more…)

bash function – git-patch()

We’ve been trying to review more Drupal 8 patches on Drupal.org with this workflow:

$ cd #to your local Drupal 8 Dir.
$ curl https://drupal.org/files/patch_url... | git apply --stat
$ curl https://drupal.org/files/patch_url... | git apply --check
$ curl https://drupal.org/files/patch_url... | git apply
# If no errors occur you can use
$git am --signoff < fix_empty_poster.patch

I found that be cumbersome so I created a bash function to simplify this.
Usage example: $ git-patch stat URL.patch
That triggers a

  • wget to retrieve the file,
  • runs $ git apply –stat
  • and prompts you for the next step.

In addition if you call the function with no vars it returns a simple usage message.
It works great, it’s more efficient and I don’t have to refer back to the patching best-practices if I forget*.
(more…)

Drupal DB backup bash script with Drush and Git

I like to make incremental backups of my drupal databases. To do that I’ve tried combine the best practices* into one bash script that I can run periodically and easily.
The end result is a bash function that’s easy and user friendly.
It works by leveraging Drush aliases and the drush sql-dump command in combination with git.

Usage is simple. From the command line:

$ dg_db_backup drush.alias "commit message" 

Note: dg_db_backup -> drush git database backup
(more…)

Branching with Git – keeping remote and local sync'd

Max pointing me to his method of branching, inspired by: http://www.zorched.net/2008/04/14/start-a-new-branch-on-your-remote-git-repository/

Which creates a branch on the remote origin and then pulls it down and tracks it locally.

The author created a bash script and I wanted to make that a function to keep in my .bashrc file;

(more…)

Un-track files in git

Recently I realized I wanted to un-track a few files in one of my git repositories for a drupal 6 site. These were files that weren’t portable between the prod, staging and dev servers.
One example would be the drushrc file. Aegir creates this file and it contains info specific to the server the site is on.
So I went looking for a way to un-track but keep the file.
I learned from experience that ‘git rm’ (the remove command) is not quite right, but if you add ‘–cached’ to the command you’re all set.

So, if you have a file being tracked by git and you want to get rid of it you can use this command

git rm --cached file/name

Ref: http://source.kohlerville.com/2009/02/untrack-files-in-git/

In addition, you should add the file to your .gitignore document.

Now when you run,

git status

or

git commit

the offending file wont be included.

Hooray!