This tutorial will help you get started with Git and Github. It is target towards Git n00bs.
Download the required Git softwares from here
If you want to make a new directory managed by Git then you have to first initialize it.
$ mkdir myapp
$ cd myapp
$ git init
This creates a new directory .git
and add few git related content there. All the sourcecode that you will commit will be place here.
Create a new file inside myapp
directory using your favorite editor and add some content to it as shown below.
On nix machines you can do the following.
$ cd myapp ## In case you are not in myapp directory
$ echo "hello Git" >> hello.txt
$ git status
Tracking an untracked file
$ git add hello.txt
To add multiple files do the following
$ git add --all
$ git commit -m "adding hello.txt"
$ echo "hey all" >> hello.txt
Now as the file is already in the Git index so you can add and commit using one command.
$ git commit -am "modified hello.txt"
$ git log
If you want to see in one line
$ git log --oneline
You can add an alias and make things better like as shown below. Alias let you write your own commands.
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit
Now you can use git lg
* 717e2fc - (HEAD, master) modified hello.txt (2 minutes ago)<Shekhar Gulati>
* 1d10050 - adding hello.txt (3 minutes ago)<Shekhar Gulati>
(END)
Signup for Github
Setup SSH keys. Copy your public key in your <User_Home>/.ssh keys. Windows uses please use Github for Windows that will set up SSH for you. https://help.github.com/articles/generating-ssh-keys/
Create a new Git repository
Add a new remote pointing to the Github repository.
$ git remote add origin git@github.com:shekhargulati/myapp.git
$ git push -u origin master
Add multiple Git remotes
$ git remote add remote1 git@github.com:shekhargulati/myapp1.git
$ git remote add remote2 git@github.com:shekhargulati/myapp2.git
$ git remote add remote3 git@github.com:shekhargulati/myapp3.git
$ git clone git@github.com:shekhargulati/myapp.git
You can also give another name
$ git clone git@github.com:shekhargulati/myapp.git myapp2
$ git pull
$ git reset --soft HEAD~1
$ git rm -f hello.txt
Always work on your features in branches
$ git checkout -b my_new_feature
Now you will inside my_new_feature
branch
Make a change, commit it, checkout master, and then merge
$ git checkout -b my_new_feature
$ echo "abc" >> hello.txt
$ git commit -am "my change"
$ git checkout master
$ git merge my_new_feature