Git for Short-Term Memory

I have a horrible memory. I think I am strewn over too many projects with way too many tools at my disposal. I forget some of the tools I’ve used in the past if I haven’t touched it in few months.

Here are some of my notes on git.

Basic Commands to Remember

# starting from scratch
mkdir <proj>
cd <proj>
git init
git add README
git commit -m 'some comment'
git remote add origin https://<your_git_location>
git push origin master
git pull

# cloning from existing project
git clone .
git add <somenewfile>
git commit -m "my comment"
git push
git push origin master
git push <remote_repos> master

# if you need to delete or modify the remote location
git remote show
git remote -v
git remote rm badorigin
git remote set-url badorigin

# setting up multiple remote repositories (e.g., bitbucket)
git remote -v
  gc_msp430ant (fetch)
  gc_msp430ant (push)
  gh_msp430ant (fetch)
  gh_msp430ant (push)
git remote add gc_msp430ant
git remote add goog <google_git_url>
git remote add bitb <bitbucket_git_url>
git push goog master
git push bitb master

Forking and Pull Requests

# using github, there's "fork" link on top of the original proj

# clone the forked proj
git clone

# add the original repo to the remote
git remote add upstream git://

# pulls in changes not present in your local repos
git fetch upstream

# git merge upstream/master
git merge upstream/master

Creating your own branch

git branch mybranch
git checkout mybranch
# or shortcut
git checkout -b mybranch

# to switch between branches
git checkout master
git checkout mybranch

# makes master the active branch
git checkout master
# merges the commits from mybranch into master
git merge mybranch
# deletes the mybranch
git branch -d mybranch

Setting Up SSH and Your Own Git

This link provides some rudimentary steps in configuring your own server as git repository:

Set up SSH public key and copy it to your homedir

ssh-keygen -t rsa -f ~/.ssh/id_rsa.blah -C "some git"
touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.blah" >> ~/.ssh/config
# the content of this file needs to be saved under your account on remote git server
cat ~/.ssh/

Login to your custom git server <>

vi ~/.ssh/authorized_keys
# now paste your public key in there. make sure you don't have any newlines in this string!

Logout and try logging back in

If you can login to without a pashword, you are good to go

Pull down the files I’ve checked into git

mkdir -p git/monbaby
cd ~/git/monbaby
git clone .

Check out the README

# make some comments and save

Check in the README file

git add README
git commit -m "comment from $USER"
git push origin master

Next time, just do git pull

Don’t do clone unlesh you want to repull the entire thing

git pull