Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Another good resource is Think Like A Git, a site who's main page states "Git shouldn't be so hard to learn."

Finally, Git Best Practices is an excellent page with tons of information, overview and links to other good resources about best-practice usage of git.

Git Merge Strategies

Git has many "strategies" you can use while merging. Read the following carefully:

...

This is a compilation of some potentially useful git commands and/or aliases

 

1) Command Line commit graph

...

PITFALL - must be run against every new checkout of the repository.  I'm not sure if this means when you swap branches, but I suspect it may.

3) Ignoring whitespace changes when a rebase fails

Sometimes when you go to do a rebase that should be simple, git fails and tells you that the entire file has changed.  It may output something like this.

Code Block
M	pom.xml
<stdin>:15: trailing whitespace.
				<groupId>log4j</groupId>
<stdin>:16: trailing whitespace.
				<artifactId>apache-log4j-extras</artifactId>
<stdin>:17: trailing whitespace.
				<version>1.1</version>
<stdin>:18: trailing whitespace.
			</dependency>
<stdin>:19: trailing whitespace.
warning: squelched 1 whitespace error
warning: 6 lines add whitespace errors.

This indicates that there have been whitespace changes.  Unless you're using python however, these probably aren't relevant and letting git sort them out will work fine.  To do this, pass the --ignore-whitespace option to rebase.

Alternatively, you could run this command to make it so whitespace is automatically ignored unless you want it to be relevant:

Code Block
git config --global apply.ignorewhitespace change

This is documented under the git-apply man page.

4) Recovering from terrible things happening to your git repository

Check out this blog post: http://www.programblings.com/2008/06/07/the-illustrated-guide-to-recovering-lost-commits-with-git/

Not really a git trick, but a github convenience.  Repositories on github can have their default branch specified.  This is useful to reduce drag and prevent worry, by making github automatically select the correct branch for a pull request to go into.

Simply go to your github repository's page and click the admin link (hint: you need admin privileges), right near the top of the page there's a setting called "Default Branch".