Miles to go ...

Git it

Getting started

Configuring your local git environment

  $ git config --global user.email "prataprc@gmail.com"
  $ git config --global user.name "Pratap Chakravarthy"
  // If you want to change this, please re-run 'repo init' with --config-name

Environment can be configured:

Initial commit

Github suggests following commands when creating a new repository.

git remote add origin git@github.com:<username>/<reponame>.git
git push -u origin master

Some of the standard commands

$ git remote -v                        // to list remote branches tracked.
$ git remote add <remote-name> <url>   // to add a remote branch
$ git branch                           // short list of local branches
$ git branch -d <branchname>           // delete a local branch
$ git branch -f <branch> <start-point> // reset branch to a starting point
$ git branch --set-upstream-to origin master // local branch track a remote
$ git branch <new_branch_name> [sha1]  // Create new branch out from a commit
$ git checkout master                  // to remove a detached commit.
$ git commit -v         // display changes inside the editor during commit

Setting up remote

We can also add remote repository with a different name, for example github instead of origin (which obviously already exists in your system), like this:

git remote add github git@github.com:<username>/<reponame>.git

Remember though, everywhere in the tutorial you see origin you should replace it with github. For example,

git push origin master
# should now be
git push github master.

However, if you want to see what that origin which already exists is, you can do a git remote -v. If you think this is there by some error, you can remove it and add the proper one by doing this:

git remote rm origin
git remote add github git@github.com:<username>/<reponame>.git

Checkout a remote branch as current branch

$ git checkout <remote>/<branch> -b <branch>

Checkout a local branch as current branch and set a remote branch to track the local branch.

$ git checkout -b <branch> --track <remote>/<branch>

Push a local-branch to remote-branch. This also creates a new branch in remote if remote-branch-name does not exist already.

$ git push <remote-name> <local-branch-name>:<remote-branch-name>