Wednesday, December 07, 2011
You need A feature and you know how to make it by extending B, an open source project repo hosted on GitHub.
You first should fork B repo, edit, test and commit your changes.
Than you send your pull request and you’re done.
After some inactivity on your fork your local repo is outdated, how can you update your fork getting code from the main repo?
-
Add upstream remote to track main repo
$ git remote add upstream git://github.com/octocat/Spoon-Knife.git
-
Fetch upstream remote in your local repo
$ git fetch upstream
-
Merge upstream/master in your current branch to apply updates
$ git merge upstream/master
Resources:
GitHub Help - Fork a repo
Monday, December 05, 2011
I often forget to mention issues or documentation in commit messages, how to fix them?
To fix the latest commit message run
$ git commit --amend
edit and save the buffer. Done.
Want to edit an old commit message?
If you find a mistake in an older commit, but still one that you have not yet published to the world, you use git rebase in interactive mode, with git rebase -i marking the change that requires correction with edit.
Resources:
Stackoverflow - How do I edit an incorrect commit message in git?
Git Community Book - Undoing in Git - Reset, Checkout and Revert
Sunday, December 04, 2011
Git stash is great.
You can forget for a moment about updates you’re working on to focus on the nth unexpected event.
Use git stash to save the current state of your work.
$ git stash save "work in progress for foo feature"
This command will save your changes away to the stash, and reset your working tree and the index to match the tip of your current branch.
Then handle the unexpected event, fix bugs, update code, write tests.
$ git commit -a -m "Fix typo"
After that, you can go back to what you were working on with git stash apply:
$ git stash apply
Updates saved to stash are queued, if you run git stash list you can see which stashes you have saved.
$ git stash list
stash@{0}: WIP on develop: 51bea1d Update license
stash@{1}: WIP on master: 9705ae6 Fix images
Then you can apply them individually with git stash apply
stash@{1}.
You can clear out the list with git stash clear.
Source: Git Community Book - Stashing