Skip to content

Git and Github

Basheer Subei edited this page Apr 4, 2015 · 11 revisions

Git Learning Resources

  • These really easy tutorials from Atlassian
  • Great comprehensive documentation at git-scm.com, has books, references, and video tutorials.
  • Git Magic explains how git works like it's magic (no need to explain how it works on the inside, just what it does).

Git Tips

  1. Pull with rebase instead of merge: git pull --rebase. Because branch merges in git are recorded with a merge commit, they are supposed to be meaningful—for example, to indicate when a feature has been merged to a release branch. However, during a regular daily workflow where several team members sync a single branch often, the timeline gets polluted with unnecessary micro-merges on regular git pull. Rebasing ensures that the commits are always re-applied so that the history stays linear.
  2. Set up your terminal prompt to display git status and stuff like Brandon Keepers (he shows how here).
  3. Set up aliases for common/long commands to save time.
  4. Try git log --graph --remotes --abbrev-commit --branches=* --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' to graph out all commits and show all branches on all remotes (make this into an alias). This great shortcut was taken from FredKSchott.
  5. Check out hub for epic ways to use github from the git command line.
  6. Use git-completion script so your terminal auto-completes git commands. More tips here

How to synchronize your fork with upstream (main IGVC repo)

  1. Assuming you already have a fork of the main repo (we'll call it "upstream") on GitHub, go to your repo directory in Terminal (just cd /my/repo/directory/, try git status just to check that you're in the correct directory and all's well).
  2. Add a new "remote" (fancy word for the URL to a git repo you would like to pull/push from. In fact, you already have a remote by default named "origin", which points to your fork on the repo). We'll add a new remote called "upstream". Just type this git remote add upstream https://github.com/chicagoedt/Software_IGVC.git
  3. Now fetch from upstream (get the new commits that have been pushed there since you last forked/fetched). The command is git fetch upstream development (notice we're using development branch; change it if necessary in other situations).
  4. Make sure you're on development branch using git checkout development. Now merge the new changes from upstream's development branch into your local development branch using git merge upstream/development.
  5. If you have any conflicts, then use git status to check which files have conflicts, and edit those files to look like you want them (usually you'd just remove changes you didn't want). Now you can commit and push as normal.
Clone this wiki locally