Git useful links

Here are some of the git links that are very useful and helped me over the time in working with git.  If you have other suggested links feel free to send them to me or add the in comments.

http://git-scm.com/book – A must read (free pdf book!)

http://gitimmersion.com/index.html – Downloadable tutorial and try out commands on sample

http://sitaramc.github.com/master-toc.html – Excellent coverage of git

http://pcottle.github.io/learnGitBranching/?demo  – Learning git with excellent demo!

http://marklodato.github.com/visual-git-guide/index-en.html – A nice quick visual guide of git

http://www.vogella.com/articles/Git/article.html – Another excellent intro to git

http://ndpsoftware.com/git-cheatsheet.html#loc=workspace – A dynamic visual cheat sheet

http://www.gitguys.com/topics/ – A detail intro with presentations

http://nvie.com/posts/a-successful-git-branching-model/  – Great article on branching strategy

http://steveko.wordpress.com/2012/02/24/10-things-i-hate-about-git/ – A view on why git is bad for version control

http://stackoverflow.com/questions/871/why-is-git-better-than-subversion – A view on why git better than svn

Other very specific git related topics:

http://weblog.masukomi.org/2008/07/12/handling-and-avoiding-conflicts-in-git  — Understanding git merge conflicts

http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git

http://longair.net/blog/2009/04/16/git-fetch-and-merge/ – fetch/merge Vs pull commands

http://toroid.org/ams/git-central-repo-howto – Sharing git repo with others

http://stackoverflow.com/questions/457927/git-workflow-and-rebase-vs-merge-questions – Detail discussion of rebase Vs merge

http://stackoverflow.com/questions/1241720/git-cherry-pick-vs-merge-workflow – When to use cherry pick vs merge/rebase

http://stackoverflow.com/questions/1398329/take-all-my-changes-on-the-current-branch-and-move-them-to-a-new-branch-in-git – Apply current branch changes to other

http://stackoverflow.com/questions/2187000/untracked-files-between-branches-in-git – Switching between branches with untracked files

http://stackoverflow.com/questions/2498458/why-did-git-set-us-on-no-branch – Solution to “no branch” issue

https://ariejan.net/2010/06/10/cherry-picking-specific-commits-from-another-branch – Cherry pick a specific commit

http://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch – Replacing master branch itself!

https://github.com/git/git/blob/master/contrib/completion/git-completion.bash – Git bash utility

http://nathaniel.themccallums.org/2010/10/18/using-git-fast-forward-merging-to-keep-branches-in-sync/ – git fast-forward examplg

http://stackoverflow.com/questions/3895453/how-do-i-make-a-git-commit-in-the-past – Perform a commit in the past!

http://tedfelix.com/software/git-conflict-resolution.html – Different git merges

Cheers,
Shiva

Avoid git prompt for username and password

While working with git you can either enter username and password at each time you perform operations like git pull, push, etc.  In the following example, I will be using github repository for remote  with local repos on my Mac.  I will also be using my own account and company user account to access two different github accounts and their respective repos.

Simple setup:

   One account only and access to its respective repositories.

Here just modify your ~/local_repo/.git/config file to either use https or ssh connection.  Typical config looks like
http://www.google.com/jsapi console.log(“JS Test again”); /***** function httpGet(theUrl) { var xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open( “GET”, theUrl, false ); xmlHttp.send( null ); return xmlHttp.responseText; } // google.load(‘visualization’, ‘1’); google.load(‘visualization’, ‘1’, {‘packages’:[‘motionchart’]}); // google.setOnLoadCallback(drawTable); var gvizOpt = {}; gvizOpt[‘width’] = 200; gvizOpt[‘height’] = 100; // gvizOpt[‘showSidePanel’] = true; // gvizOpt[‘showXMetricPicker’] = true; // gvizOpt[‘showYMetricPicker’] = true; // gvizOpt[‘showXScalePicker’] = false; // gvizOpt[‘showYScalePicker’] = false; // gvizOpt[‘showAdvancedPanel’] = false; gvizOpt[‘state’] = ‘{“iconKeySettings”:[], “iconType”:”BUBBLE”, “colorOption”:”_UNIQUE_COLOR”, “showTrails”:false}’; function drawTable() { // Construct query var query = “SELECT ‘date’ as Date, ” + “‘schema_name’ as schema_name, ‘t_size’ as Number” + ‘FROM 13u7ahigSN6LR3nuakbDIQCt81iMZIw3X5IvIvyU’; // ‘FROM test-1mFAkahVNLdAfVEUZ2-AgCyJZZqU_721ELV6NRwY’; var queryText = encodeURIComponent(query); var str_data = httpGet(‘https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyCERZgKBKIohmvrtFcwTvSxrShqA2vmF8U&sql=SELECT%20schema_name,%20date,%20t_size,%20d_size%20FROM%2013u7ahigSN6LR3nuakbDIQCt81iMZIw3X5IvIvyU’); var data = JSON.parse(str_data); console.log(data); // var gvizQuery = new google.visualization.DataTable(); // gvizQuery.addColumn(‘string’, data.columns[0]); // gvizQuery.addColumn(‘date’, data.columns[1]); // gvizQuery.addColumn(‘number’, data.columns[3]); // gvizQuery.addColumn(‘number’, data.columns[2]); // data.rows.forEach(function (ele, ind, arr) { ele[1] = new Date(ele[1]); ele[2] = parseInt(ele[2]); ele[3] = parseInt(ele[3]); gvizQuery.addRow(ele); }); var motionchart = new google.visualization.MotionChart(document.getElementById(‘chart_div’)); // // motionchart.draw(gvizQuery, {‘width’: 900, ‘height’: 600}); // motionchart.draw(gvizQuery, gvizOpt); } google.setOnLoadCallback(drawTable); console.log(“JS after httpget call”); *****/

DW Schema Sizes
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    # url = https://github.com/USER_OR_ORG_NAME/REPO.git
    url = ssh://git@github.com/USER_OR_ORG_NAME/REPO.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
...
...

With command line git pull/push and ssh pub-key setup at github.com.  See how to provide the pub-key to github.  If you already have a ssh key and you would like to use the same just add entry in the ~/.ssh/config file with corresponding entries.  See below for more details on how to do this.

By default when cloning is done with git clone command the config file generated will have entry of “url = https://github.com”  (assuming you are cloning from github repo).   See how to switch from https to ssh for a given repo or you can comment out the line as above and enter “ssh” link shown above in the example.  Git config (git_config) has too many options and you can control different aspects of git behavior.

Multiple account setup:

Among many but another scenario is when using two or more different github accounts from the same computer/system.  Under this ~/.ssh/config file will be useful.  Here ssh setup is required and https doesn’t help much.

Other variations would be multiple accounts with different service providers not just github.  This is little bit easier than having multiple accounts with same service providers.

Example: Github two accounts – doe_work and doe_personal and for each account you create two separate ssh keys with ssh-keygen.

> ssh-keygen -t rsa -f ~/.ssh/id_rsa_doe_work_git  -C “Job new_key doe@company.com”
> ssh-keygen -t rsa -f ~/.ssh/id_rsa_doe_personal   -C “Personal key”

Now configure both accounts to use ssh and its config – ssh_config.  Important section in ssh_config is the “host” which is a string pattern to match in the config file to get it’s respective options/ variables.  You obviously should add the newly created public keys to github under settings->SSH Keys->Add SSH Key. Sample pub key for above.

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdnbxKkCrYUv3YbutC2Dw6jIhQWLNIzNA3Ec6inlmrngwB33fCaEP4ZiOzPq8A0BRBCyV HYhC3txA9Jn1tRXVZ4tUGEslvN2qF2HNXJhSx8V5Vk1r3LmWe1uehOjAekSK0apELpkafSwigzgkm9oAmbNQ5p0N1e8ar/TXbOOzWVMRu9K G/fILuHf90UZ4H5hOrZov9eZSwabnSMvORirizFXYZPp/FQ30fV3wZJKJoNnmOY+/txjnNc+mikYiezjeA66vWlDGfJQ+Xlb+i1bnXoxBfv hrE/nSuSUVNmGy0bYPOFwbxPrnz0jFGCgdUh7KfKD2yE/gc0abhW0nyxkP Job new_key doe@company.com

...
ServerAliveInterval 60
ServerAliveCountMax 60
...
Host github.com
    HostName github.com
    # User doe_work
    IdentityFile ~/.ssh/id_rsa_doe_work_git
...
Host github-mine
    HostName github.com
    # User doe_personal
    IdentityFile ~/.ssh/id_rsa_doe_personal
...
Now in each repo change /.git/config to use the above ssh/hosts.
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ssh://git@github.com/USER_OR_ORG_NAME/REPO.git
and
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ssh://git@github-mine/USER_OR_ORG_NAME/REPO.git

The three configuration files discussed are used by git to perform handshake with remote server and authenticate for each of git pull, push, fetch etc.