- Describe reasons for using version control
- Explain what Git is and why we use it
- Start a repo by initializing locally
- Add and commit changes
- Check the status of a repo
- Explain what role GitHub plays
- Create a repo on GitHub
- Clone and fork existing repositories
- Push commits to a remote repo
- Explain the difference between fetch and pull
- Explain the difference between clone and fork
You Do - 10 min
Demonstrate the need for Git
https://gist.github.com/mdang/c601cf7edc3c28f6f580
Git is a distributed version control sytem. This means that clients don't just check out the latest snapshot, they fully mirror the entire repository. There's no single point of failure. Every clone is a full backup of the data.
QUESTION: Why do we use Git? Why not just timestamp directories and save multiple versions?
Git allows you to:
- Revert files back to a previous state
- Revert the entire project back to a previous state
- Compare changes over time
- See who last modified something that might be causing a problem
- See who introduced an issue and when
It's almost impossible to lose a backup of your work if you create a snapshot (commit) at any point. It gives you freedom to explore and try new things without the worry of losing your work. For the most part data is added not deleted
Show diagram of what it means to be distributed vs centralized. Focus on local part, and explain by end of class we'll work in GitHub for a centralized store.
- We are going to focus on the local part now, then move on to working with a remote repository
- Explain how working locally differs from SVN
- speed
- don't need to be connected to the internet to save progress, you could be working with it on an airplane
- can take chances and not worry about how it will affect others
- Explain that each checkout is a full copy of the repository
The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.
The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.
The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit.
2 minutes
Describe the most important thing you learned and identify any area of confusion.
git init
touch list.html
subl list.html
git status
- Untracked files - Any files in the working directory that were not in the last snapshot and are not in the staging area
- Tracked files
- Unmodified
- Modified
- Staged
git add list.html
NOTE: 'git add' stores a snapshot of the file as is, if you remember something and go back to edit it, it must be staged again if you want those changes in the commit.
Check git status
now
git commit -m "Short description about the commit"
git mv list.html list2.html
git rm list.html
git log -p -2
- -p displays the diff in each commit
- -2 limits the diff to two lines
git log --pretty=oneline
20 min
https://gist.github.com/mdang/3065eedb93d9da10ee4e
- work in teams
- backup our data in case our machine crashes
- resume
- social
A clone is a copy of an existing repository. We can create as many clones as we want, wherever we want.
Forking creates a copy of someone else's GitHub repo to your GitHub account. The forked repo is not perfectly identical - but it includes all the same source files, issues, and commit history.
- Used for open source contributions so that not everyone has to have write access to the code in order to contribute
- Propose bug fixes
We Do
git clone git@github.com:ga-students/wdi-atx-2-class.git
Search for any popular repository and show how easy it is to fork into our own repository
NOTE: Students will be using a variation of the following link to submit homework:
https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
- Fork the homework repo
- Clone your version of the repo
- Add a remote
upstream
- To get the latest updates, they will run
git pull upstream master
- They will then submit a pull request
NOTE Initialize the repo with a README or there won't be a master branch
You Do
Clone the repository you just created on GitHub
git push
/ git push origin master
git fetch
- Obtains the latest updates from the remote repositorygit merge
- Merges the new updates with your existing working copygit pull
- A combination of both fetch and merge
Update the class repo with some new content. Have the students do a git pull
to get the updates
- Branching
- Working on the same repository with other developers
- Pull requests
- Merge conflicts