Skip to content

Git And GitHub Tips

Thomas Thomassen edited this page Sep 13, 2013 · 12 revisions

Diffs and Whitespace

Append ?w=1 to GitHub diff urls to ignore whitespace. For example

Before: https://github.com/SketchUp/sketchup-stl/commit/18c8d6e9aaf9d21b81a3b132fd2a76bd5657fa7a

After: https://github.com/SketchUp/sketchup-stl/commit/18c8d6e9aaf9d21b81a3b132fd2a76bd5657fa7a?w=1

Here's some code for a bookmarklet to append ?w=1 to the current url:

javascript: window.location = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?w=1';

(via http://confreaks.com/videos/1229-aloharuby2012-git-and-github-secrets)


Selective Staging

You can interactively select chunks of a file to stage using git add -p filename


Symlinks

Loading extensions directly from your repository using symlinks on Windows.

  1. Run a Command Prompt as Admin.
  2. cd to your Plugins folder. cd c:/users/jim/dropbox/plugins

Linking the folder:

Plugins>mklink /d sketchup-stl C:\Users\Jim\Documents\GitHub\sketchup-stl\src\sketchup-stl

and linking the file:

Plugins>mklink sketchup-stl.rb C:\Users\Jim\Documents\GitHub\sketchup-stl\src\sketchup-stl.rb

Note - the location of your plugins folder may be different.


Remote Repos & Upstream

By default, when using GitHub Windows client, you clone your fork it just sets up your fork as the 'origin' remote. So calling git remote -v returns for my [briangbrown] fork:

origin  https://github.com/briangbrown/sketchup-stl.git (fetch)
origin  https://github.com/briangbrown/sketchup-stl.git (push)

The README is referring to adding SketchUp/sketchup-stl as a remote so you can pull in changes from this repo into your fork. Details here (which is basically the same as the link you posted) https://help.github.com/articles/fork-a-repo

So after calling git remote add upstream https://github.com/SketchUp/sketchup-stl.git calling git remote -v returns

origin  https://github.com/briangbrown/sketchup-stl.git (fetch)
origin  https://github.com/briangbrown/sketchup-stl.git (push)
upstream        https://github.com/SketchUp/sketchup-stl.git (fetch)
upstream        https://github.com/SketchUp/sketchup-stl.git (push)

And now you can get upstream changes by calling

git fetch upstream
git merge upstream/master

then push them to your fork on github by calling

git push origin master

https://github.com/SketchUp/sketchup-stl/issues/28#issuecomment-9930729


Development Branches

Some interesting topics on StackOverflow on how to deal with development feature branches and what to do with them after a feature is completed.

When you know a particular branch is going to be reused soon it's no point in closing it off. When you resume it, just merge master back into the branch with the latest changes.


References