Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
Tell us about yourself.
Version control allows you (and your team) to…
Create anything with other people, from academic papers to entire websites and applications.
Mistakes happen. Wouldn't it be nice if you could see the changes that have been made and go "back in time" to fix something that went wrong?
Do you have files somewhere that look like this?
Resume-September2013.docx
Resume-for-Duke-job.docx
ResumeOLD.docx
ResumeNEW.docx
ResumeREALLYREALLYNEW.docx
You invented your own version control!
But, we can do it so much better with Version Control tools
1990s — CVS (Concurrent Version Systems)
2000s — SVN (Apache Subversion)
2005 — Git
The first commit, April 2005
commit e83c5163316f89bfbde7d9ab23ca2e25604af29
Author: Linus Torvalds <torvalds@ppc970.osdl.org>
Date: Thu Apr 7 15:13:13 2005 -0700
Initial revision of "git", the information manager from hell
Examples: CVS, SVN
Examples: Git, Mercurial
One central server, each client (person) checks out and merges changes to main server
...NOT how Git works!
Each client (person) has a local repository, which they can then reconcile with the main server.
...this is how Git does it!
Install git
Setup name and email in git config
$ git config --global user.name "Your Name Here"
# Sets the default name for git to use when you commit
$ git config --global user.email "your_email@example.com"
# Sets the default email for git to use when you commit
$ git config --list
Setup SSH keys
SSH keys allow you to interact with your Git server without having to type your username and password all the time.
Setup the Default Text Editor
By default Git is set up to use Vim as the text editor.
(esc + :q or :q! to get out of Vim)
Follow these instructions to change your default text editor to whatever you prefer.
Go to home directory
$ cd ~/
$ pwd #make sure you're in your home directory
Create a "working directory"
$ mkdir my-repo
$ cd my-repo
Initialize repository with Git
$ git init
$ git status
Create a README.md
file in your new folder
Check repo status
$ git status
Tell Git to track our new file
$ git add README.md
$ git status
File is now tracked by Git
Open README.md
and add some more text
$ git status
Stage and commit the change
$ git add README.md
$ git commit -m "First commit. Added README to repository."
A good commit message acts like a headline to a newspaper article (but not clickbait!)
How is this all different than just saving a file?
$ git log
commit [HASH HERE]
Author: Your name <you@your-email.com>
Date: [DATE HERE]
First commit. Added README to repository.
README.md
and make some more commits.git status
regularly so that you can see what is happening at each stage!If you haven't staged/committed yet
Open README.md
and make some changes to the file.
$ git checkout README.md
Look at README.md
. Your changes are gone. You've gone back to the previous commit state.
Create new file my_new_file.txt
$ git add my_new_file.txt
$ git reset my_new_file.txt
The file is removed from staging, but your working copy will be unchanged.
Open README.md
and add some new text
$ git add README.md
$ git reset HEAD README.md
$ git status ## your changes were unstaged
$ git checkout README.md
Look at README.md
. Your changes are gone and the file is removed from staging.
Git lets you go back to any previous commit.
Open README.md
and add some new text
$ git add README.md
$ git status
$ git commit -m "Make a change I will soon regret making"
$ git log --oneline
Okay, I see the change… now how do I remove it?
$ git revert 53d23c4
# Your default editor will open here
# you can just save it and close it as is.
$ git log --oneline
Notice that the original, regrettable commit is still there, but now you also have another commit that undoes the changes introduced by the original one.
You decide what goes into version control.
You can—and should!—leave some things out.
libraries, .dotfiles, api keys...
Git shows you an easy way to do this: .gitignore
A branch is another copy of your repo that allows you to isolate changes and leave the original copy untouched. You can choose to combine these changes in whole or part with the "master" copy later.
Why Branch?
Create a new branch called my-feature
$ git checkout -b my-feature
Add new lines to README.md
$ git add README.md
$ git commit -m "Adding changes to my-feature"
See all branches. Branch with * is active
$ git branch
Switch to master
and look at README.md
$ git checkout master
Switch to my-feature
and look at README.md
$ git checkout my-feature
Copying changes from one branch to another is called merging.
Switch to master
and merge the changes from the branch my-feature
$ git checkout master
$ git merge my-feature
$ git log --oneline
What is a merge confict?
Change first line in README.md
in master
branch
$ git add README.md
$ git commit -m "Changing first line in master"
Change first line in README.md
in my-feature
branch
$ git checkout my-feature
# open README.md and change first line
$ git add README.md
$ git commit -m "Changing first line in my-feature"
Merge from master
into my-feature
$ git merge master
You will be notified of a conflict. Go to the file and fix the problem. Then commit your edits.
You will need to be logged into your GitHub account to do this.
After you click the big green button to create your repo, follow GitHub's instructions for next steps.
$ git remote add origin https://github.com/YOUR-GITHUB-USERNAME/REPO.git
$ git push -u origin master
# that -u is an option that signals that you are setting
# a tracking reference to the remote branch as the default;
# you only need to use this flag the first time
Now check out your GitHub repo online!
Now, GitHub is acting as our remote repository
Edit README.md
$ git add README.md
$ git commit -m "Updating readme file"
$ git push origin master
Now check out your GitHub repo online!
If team members are contributing to a single repo, each member of the team will want to make sure that she has everyone else's changes before pushing her own changes to the remote repository.
Always pull before you push!
Commit local changes first
$ git commit -m "My latest commit"
Get changes that have been pushed
$ git pull origin master
Git may prompt you to fix any conflicts, then commit
$ git commit -m "Fixing merging conflicts"
Now you are ready to push local changes to GitHub
$ git push origin master
There are MILLIONS of public repositories on GitHub.
There are huge open source projects (including Git!)…
…and small projects like these slides.
If you want to use or contribute to a repository, you have to fork the repository, then clone it to your computer.
A fork is just a copy of a repository, saved to GitHub.
After you fork the repository, it shows up in your repositories.
Let's Try It! Fork this repo.
You can only fork repos through the GitHub website.
To get a local copy of the fork you just made, use the git clone
command.
$ cd ../
$ git clone https://github.com/USERNAME/git-resources.git
$ cd git-resources
$ git remote -v
To sync your fork with the original repo, you need to add another remote named upstream
$ git remote -v
$ git remote add upstream https://github.com/GDIBTV/git-resources.git
$ git fetch upstream
git fetch
downloads Git references not present in your local repository, but does not modify your files (think of it like getting a table of contents rather than the contents themselves)
After you fork
and clone
a repository all pushed changes will go to your fork (origin
)
These changes do not affect the original (upstream
) repository (mostly because permissions). To do that, you need to submit a pull request.
A pull request is a GitHub feature that lets you ask the owner of the upstream repo to pull your changes in.
Pull requests can only be done through the GitHub website.
Repo owners review and decide whether to merge in the pull requests they receive.
You can learn more from the
Github Collaborating Tutorials
git-resources
repository and push to your remote.Keep in touch!