Stop pulling hair out with git

To help understand how git works, I scrambled this post on what I know about simple workflow in git. I first started my project locally and then I added VCS using ‘git init’ in the existing project’s root directory.

Then I wanted to host it on github. I did this by creating
git push -u

But if I want to skip adding “-u” everytime I push, I can do:
git remote add up

If I want to compare my local current branch commits to my remote’s branch, I need to do:
git branch –set-upstream master up/master  //replace master with your branch

To see your tracked files:
git ls-files

To see your modifications, here is neat coloured output:
git log –pretty=format:”%Cblue%h:%Cred%ce: %Cgreen%s” –name-status –graph

Make alias of above in your .gitconfig in default home directory.
hist = log –pretty=format:\”%Cblue%h:%Cred%ce: %Cgreen%s\” –name-status –graph

A common thing is to compare my local branch to remote for unpushed commits. You can do this by:
git hist origin..      //this is implied as git hist origin..master


The converse, “git hist ..origin” would show how far your remote is ahead in commits.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s