Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ashwinning/35f530be96754e71a138af842d147cf8 to your computer and use it in GitHub Desktop.
Save Ashwinning/35f530be96754e71a138af842d147cf8 to your computer and use it in GitHub Desktop.
Version control your `.bashrc` file (or any other file) with Github Gist #gistblog #ubuntu #bash

Version control your .bashrc file with Github Gist

Install Gist on your machine

If you have ruby installed (how to install ruby):

sudo gem install gist

‌If you're using Bundler:

   source :rubygems
   gem 'gist'

‌For OS X, gist lives in Homebrew

   brew install gist

Log into Gist with your Github account

If you want to associate your gists with your GitHub account, you need to login with gist. It doesn't store your username and password, it just uses them to get an OAuth2 token (with the "gist" permission).

gist --login
Obtaining OAuth2 access_token from github.
GitHub username: ConradIrwin
GitHub password:
2-factor auth code:
Success! https://github.com/settings/tokens

This token is stored in ~/.gist and used for all future gisting. If you need to you can revoke it from https://github.com/settings/tokens, or just delete the file. If you need to store tokens for both github.com and a Github Enterprise instance you can save your Github Enterprise token in ~/.gist.github.example.com where "github.example.com" is the URL for your Github Enterprise instance.

‌After you've done this, you can still upload gists anonymously with -a.

gist -a a.rb

Learn more about using the gist client.

Create a Gist with your bashrc file

Upload your .bashrc file to your account as a private gist using the following command

gist -p -o -d "My .bashrc" ~/.bashrc

Here -p specifies that you want this file to be private, -o will open a new browser tab with the gist page as soon as it's uploaded, and -d is used to add a description for your file.

Create an alias for updating your file

Open your .bashrc file with the editor of your choice, in this case I'll be using atom.

sudo atom ~/.bashrc

At the end of the file add the following command

#Gist Bashrc alias
alias gistbash="gist -u GIST_ID ~/.bashrc"

Where GIST_ID is the id of your uploaded gist file found in the URL.

Save the file and close out your editor.

Commit your changes

Either open a new terminal window or source your .bashrc by using the following command

source ~/.bashrc

Now you can run your alias every time after making a change to your .bashrc file to update your gist.

gistbash

After you run the command you should be able to see the changes reflected on the gist!

@blancNoir
Copy link

just what i was looking for, works without much fuss. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment