Chapter 1
*Apologies to Miran Lipovača
Detailed discussion/
"section content"
Overview information/
"section headers"
This is not a picture of git.
Using one git repo
Using more than one git repo
Great Good
# Make a new folder to hold your git repo.
cd /someplace/on/your/computer/
mkdir myGitRepo
cd myGitRepo
# Now make your repo.
git init
# Bask in your brilliance.
# Create a new file in your git repo! Use your imagination!
# No imagination? That's okay. Use this:
echo "# This is my git repo." >> readme.md
echo "Pretty sweet, huh?" >> readme.md
# Now check on the status of your repo:
git status
Using one git repo
Using more than one git repo
Great Good
Using one git repo
Using more than one git repo
Great Good
# Add your files to the git repository's index with `git add`.
# The index points to the set of changes that you are ready to commit.
# If you didn't have an imagination, run this:
git add readme.md
git status
# Make your first commit!
git commit
git status
Using one git repo
Using more than one git repo
Great Good
# Whoa! You were on a branch this whole time! Check it out:
git branch
# Make a new branch!
git branch myFirstBranch
git checkout myFirstBranch
# Make a new commit!
touch blarneyStone.txt
git add blarneyStone.txt
git commit
Using one git repo
Using more than one git repo
Great Good
# You can compare branches!
git diff master myFirstBranch
# Branches are discrete versions of your repo's content!
git checkout master
git branch mySecondBranch
git checkout mySecondBranch
echo "A string in a file." >> fileWithAString.md
git add fileWithAString.md
git commit
Using one git repo
Using more than one git repo
Great Good
# You can also merge branches! Way cool!
git checkout myFirstBranch
git log
git checkout mySecondBranch
git log
git merge myFirstBranch mySecondBranch
ls
git log
Using one git repo
Using more than one git repo
Great Good
are sets of code changes
are sequences of commits
are sets of branches
Using one git repo
Using more than one git repo
Great Good
Passing code between repositories is easy, safe and there are many online tools that leverage this feature to do amazing things. [1][2]
If you don't, you are boring. Please don't be boring.
Using one git repo
Using more than one git repo
Great Good
Remotes are how git repositories talk about other git repositories. A git repo will maintain a list of remotes as well as a list of all the branches it has learned about at the locations the remotes point to.
Using one git repo
Using more than one git repo
Great Good
TFS server repo
Using one git repo
Using more than one git repo
Great Good
TFS server repo
Local repo
# Check out your repo's remotes
git remote # You should only see one remote named "origin"
"origin"
Using one git repo
Using more than one git repo
Great Good
# 1) Make a new branch and add a new quote to the Quotes project!
# 2) Backup your work on your new remote repo!
git push origin your-new-branch
TFS server repo
Local repo
Go check out your work on the TFS server!
Using one git repo
Using more than one git repo
Great Good
git push origin some-branch
# this says: "Hey, local repo, copy some-branch over to the repo origin points to."
Hmm. So does that remote remember the branch you just sent?
# Let's see what our repo knows about remote branches:
git branch -a
# The output of this command reads:
#
# <remote name>/<branch name>
Using one git repo
Using more than one git repo
Great Good
Pull Requests are how git repos manage the code review process.
In the TFS web portal, find the branch you just pushed and make a pull request against the master branch.
Using one git repo
Using more than one git repo
Great Good
Pull requests are how Github repos say: "Hey there! I have a branch that could update one of your branches! Please review my branch and then perform a git-pull."
git pull <my branch>
# for more info: http://git-scm.com/docs/git-pull
Using one git repo
Using more than one git repo
Great Good
Once your pull requests (or anybody else's) are accepted, you still need to go get the new state of the project.
Using one git repo
Using more than one git repo
Great Good
To keep tabs on how other git repositories in your project are changing, you will need to get their changes regularly.
# "fetch" updates your repo's records of the remote branches
git fetch <remote name> # all branches on the remote
git fetch <remote name> <branch name> # just the indicated branch
# "pull" is a shortcut[2] that combines fetching and merging.
git pull <remote name> # fetch and merge all branches
git pull <remote name> # fetch and merge the indicated branch
are pointers to other repos
Using one git repo
Using more than one git repo
Great Good
Using one git repo
Using more than one git repo
Great Good
The power/flexibility that git gives you is simultaneously its most frustrating foil. Don't worry, there are many many CASS students and staff who will always be here to help you.
Using one git repo
Using more than one git repo
Great Good
Understanding that you have complete control over your own workflow and repo structure, the rest of this section is a list of workflows that have been used extensively and are endorsed by the Github community.
Using one git repo
Using more than one git repo
Great Good
Using one git repo
Using more than one git repo
Great Good
Using one git repo
Using more than one git repo
Great Good
Using one git repo
Using more than one git repo
Great Good
Off the top of my head: Github, Bitbucket, Bettercodes, Heroku, Travis CI, Phonegap Build ...
A note about shortcuts and 3rd party tools:
While useful, these tools tend to assume that you are using your git repos with a certain workflow. If this assumption is false you may accidentally do very bad things* to your work.
* utterly and irreversibly destroy