Simplistic Git Tutorial

Simplistic Git Tutorial

July 2014

Generally speaking ... we're looking at two separate things here, using git locally and with a service such as GitHub or Bitbucket. Using locally:

sudo apt-get install git

initialize the directory, add the items, commit

cd /dir/for/git
git init
git add -A OR git add .
#above is all to add all items. You can add specific items too
git add file1 file2 file3
git commit -m 'm is for message, add your message here'
git status #check current status

First things first, create you ssh key

ssh keygen -t rsa "email"

Copy the public key and use that for your key in GitHub/Bitbucket

cd ~/.ssh

Connecting with a remote server. Pretty much the same as above, of course we need to specify our remote location

cd /dir/for/git
git remote add origin
git push origin master

When we push origin master, we push up to our remote GitHub account.

When you are happy with you current state, you can create a branch, and work off the branch.

git branch

Move to the new branch

git checkout

Create and move to all in one

git checkout -b

Now you can do all your work on the branch, when you're happy, commit and merge it with master

git commit -m 'commit message'
git checkout master
# check the current working branch
git branch
git merge

You can either keep the branch or delete

git branch -d

For cloning a repo

git clone
cd reponame
# track it
git remote add upstream git://
git fetch upstream
# I generally do
git pull

To help keep my clones organized I create a git directory

mkdir git
cd git
git clone .....
be happy and organized

Other cool stuff

git diff
git log --graph

More disclaimer, again, I am not a pro at this, its mainly from what I've picked up from personal use. There is obviously so much more that can be done, and possibly better ways to do stuff. For my configs and such I generally don't branch, but when I was coding, I would definitely branch.

Hopefully I didn't leave anything important out.

Edit: IIRC when you add a remote origin,if its added as https, not ssh. You can change that with set-url

git remote set-url origin