Managing Your Emacs Configuration with Git and GitHub

This guide will walk you through the process of version controlling your Emacs configuration using Git and hosting it on GitHub.

Prerequisites

  • Git installed on your system
  • GitHub account
  • Basic knowledge of Git commands
  • Emacs installed with a configuration you want to share (see this post)

Step-by-Step Instructions

1. Create an Empty Repository on GitHub

  1. Go to GitHub (https://github.com)
  2. Click the “+” button in the top-right corner
  3. Select “New repository”
  4. Name it .emacs.d
  5. Leave it empty (don’t initialize with README)
  6. Click “Create repository”

2. Initialize Git in Your Local .emacs.d

Open your terminal and navigate to your .emacs.d directory:

cd ~/.emacs.d
git init

3. Create .gitignore

Before committing, create a .gitignore file to exclude unnecessary files:

# Create and edit .gitignore
echo "# Backup files
**~

# Auto-generated files
auto-save-list

# Cache files
eshell/

# elpa packages
/elpa/
" > .gitignore

4. Commit Your Configuration

Add and commit your files:

git add init.el .gitignore
git commit -m "Initial commit: Add basic Emacs configuration"

5. Connect to GitHub

Link your local repository to GitHub (replace YOUR-USERNAME with your GitHub username):

git remote add origin git@github.com:YOUR-USERNAME/.emacs.d.git
git branch -M main

6. Push to GitHub

Push your configuration to GitHub:

git push -u origin main

Best Practices

  1. Commit Messages: Write clear commit messages explaining what changes you made and why.
  2. Regular Updates: Commit changes regularly as you modify your configuration.
  3. Documentation: Consider adding a README.md to explain your configuration.

Basic Directory Structure

After setup, your .emacs.d should look like this (ignored files are omitted):

.emacs.d/
├── .git/
├── .gitignore
└── init.el

The state of init.el at the conclusion of this article can be found [here](https://github.com/Rindrics/.emacs.d/blob/846614662ab89aec0123578978bb0cf11d31fb3e/init.el


comments powered by Disqus