-
Notifications
You must be signed in to change notification settings - Fork 23
Git and Github
Basheer Subei edited this page Apr 4, 2015
·
11 revisions
- 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).
- 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. - Set up your terminal prompt to display git status and stuff like Brandon Keepers (he shows how here).
- Set up aliases for common/long commands to save time.
- 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. - Check out hub for epic ways to use github from the git command line.
- Use git-completion script so your terminal auto-completes git commands. More tips here
- 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/
, trygit status
just to check that you're in the correct directory and all's well). - 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
- 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). - 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 usinggit merge upstream/development
. - 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.