I use git version control for maintaining my code. The basic initial commands for placing my stuff in source control is as follows.


I have a local bin/ directory which contains C++ code, output binaries, as well as my bash config files, aliases and emacs keybindings.
I use this to maintain shell customizations as well as any shell related tools I may need.
So I create a dotfiles/ directory in bin/. in this directory I then have a structure like so:

eamoc@knut:~$
➜ tree bin
bin
└── dotfiles
├── bash
│   ├── aliases
│   ├── config
│   └── env
└── bashrc

2 directories, 4 files



At the root of ~/bin/ I create a git repository.

eamoc@knut:~/bin$
➜ git init
Initialized empty Git repository in /home/eamoc/bin/.git/
eamoc@knut:~/bin$

Next I add everything under the bin/ directory to the next checkin. These files are now queued for committal to the local repository.

eamoc@knut:~/bin$
➜ git add .


Finally commit the files with a short message:

eamoc@knut:~/bin$
➜ git commit -m "Shell config files first commit"
[master (root-commit) 8155437] Shell config files first commit
6 files changed, 310 insertions(+)
create mode 100644 .gitignore
create mode 100644 dotfiles/bash/.bashrc
create mode 100644 dotfiles/bash/aliases
create mode 100644 dotfiles/bash/config
create mode 100644 dotfiles/bash/env
create mode 100644 dotfiles/bashrc



You can list the files that are in the repo:

eamoc@knut:~/bin$
➜ git ls-files
.gitignore
dotfiles/bash/.bashrc
dotfiles/bash/aliases
dotfiles/bash/config
dotfiles/bash/env
dotfiles/bashrc

You can also view a log of your recent activity:

eamoc@knut:~/bin$
➜ git log
commit 8155437746e7785c4f2c0c5ef8e0f9670f9b89f7
Author: Eamonn Costello
Date: Thu Aug 28 10:04:17 2014 +0100

Shell config files first commit
eamoc@knut:~/bin$


Or git log --stat. The --stat flag provides an ASCII chart with more information. the '+' indicates the number of lines that were added, while a '-' would indicate the number of files that were removed.

eamoc@knut:~/bin$
➜ git log --stat
commit 8155437746e7785c4f2c0c5ef8e0f9670f9b89f7
Author: Eamonn Costello

Date: Thu Aug 28 10:04:17 2014 +0100

Shell config files first commit

.gitignore | 1 +
dotfiles/bash/.bashrc | 114 +++++++++++++++++++++++++++++++++++
dotfiles/bash/aliases | 9 +++
dotfiles/bash/config | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++
dotfiles/bash/env | 2 +
dotfiles/bashrc | 24 ++++++++
6 files changed, 310 insertions(+)


I have a file in the repo that I don't need: dotfiles/bash/.bashrc
I can delete it from the repo by doing:



eamoc@knut:~/bin$
➜ git rm dotfiles/bash/.bashrc
rm 'dotfiles/bash/.bashrc'


I also want to add some aliases to dotfiles/bash/aliases:

eamoc@knut:~/bin$
➜ cat dotfiles/bash/aliases | grep git
alias gst 'git status'
alias gl 'git pull'
alias gp 'git push'
alias gd 'git diff | nano'
alias gc 'git commit -v'
alias gca 'git commit -v -a'
alias gb 'git branch'
alias gba 'git branch -a'


Now if I do:

eamoc@knut:~/bin$
➜ git status

On branch master
Changes to be committed:
(use "git reset HEAD
..." to unstage)

deleted: dotfiles/bash/.bashrc

Changes not staged for commit:
(use "git add
..." to update what will be committed)
(use "git checkout --
..." to discard changes in working directory)

modified: dotfiles/bash/aliases


I can see that a file was deleted and a file was modified. As before these need to be committed before the repo is updated.

eamoc@knut:~/bin$
➜ git commit -v
[master cf82113] Added git aliases to dotfiles/bash/alias Deleted dotfiles/bash/.bashrc
1 file changed, 114 deletions(-)
delete mode 100644 dotfiles/bash/.bashrc

If i do a git log --stat again, I can see the changes:

eamoc@knut:~/bin$
➜ git log --stat
commit cf8211303720064aac78bcf15bdc483f631c13a0
Author: Eamonn Costello

Date: Thu Aug 28 16:24:11 2014 +0100

Added git aliases to dotfiles/bash/alias
Deleted dotfiles/bash/.bashrc

dotfiles/bash/.bashrc | 114 --------------------------------------------------
1 file changed, 114 deletions(-)

commit 8155437746e7785c4f2c0c5ef8e0f9670f9b89f7
Author: Eamonn Costello

Date: Thu Aug 28 10:04:17 2014 +0100

Shell config files first commit

.gitignore | 1 +
dotfiles/bash/.bashrc | 114 +++++++++++++++++++++++++++++++++++
dotfiles/bash/aliases | 9 +++
dotfiles/bash/config | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++
dotfiles/bash/env | 2 +
dotfiles/bashrc | 24 ++++++++
6 files changed, 310 insertions(+)
eamoc@knut:~/bin$


Finally, I want to push this repo up onto GitHub, so I'll never lose my configs and aliases and other tools etc.
Log in to github.com and create a repository. 

I created https://github.com/eamoc/BashShellConfig.git

First I set the remote repo:
eamoc@knut:~/bin$
➜ git remote add origin https://github.com/eamoc/BashShellConfig.git

Then I verified it:
eamoc@knut:~/bin$
➜ git remote -v
origin https://github.com/eamoc/BashShellConfig.git (fetch)
origin https://github.com/eamoc/BashShellConfig.git (push)

Finally I pushed the changes in my local repo up to git hub.
eamoc@knut:~/bin$
➜ git push origin master
Username for 'https://github.com': eamoc
Password for 'https://eamoc@github.com':
Counting objects: 10, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (10/10), 3.45 KiB | 0 bytes/s, done.
Total 10 (delta 1), reused 0 (delta 0)
To https://github.com/eamoc/BashShellConfig.git
* [new branch] master -> master


And thats it. All my shell configuration settings are now on github. All I have to do if I have a new machine is pull down this repo to my local directory, wherever that may be and source it, and I'm good to go.