Nina Zakharenko - Introduction to Git - Start SLC 2015
-
Upload
nina-zakharenko -
Category
Technology
-
view
433 -
download
0
Transcript of Nina Zakharenko - Introduction to Git - Start SLC 2015
![Page 1: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/1.jpg)
Start slc Salt Lake City, UT
January 31st, 2015
![Page 2: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/2.jpg)
Intro to gitPRESENTED
BY
Nina Zakharenko
AND
![Page 3: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/3.jpg)
PART 1
Overview
WHY USE VERSION CONTROL
COMMITTING TO YOUR REPOSITORY
GIT IS NOT GITHUB
REPOSITORY CREATE YOUR FIRST GIT PROJECT
![Page 4: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/4.jpg)
PART 2
OVERVIEW
FINAL EXERCISE FORKING (IS NOT A DIRTY WORD)
BRANCHES PULL REQUESTS SHARING YOUR WORK
![Page 5: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/5.jpg)
?
WHY USE VERSION CONTROL
![Page 6: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/6.jpg)
Have you ever found yourself creating multiple versions of a file to “save” your changes? !Do you make multiple copies of files to make sure you have a working backup?
VERSION PROBLEMS
AND VERSIONS ARE ALL OF THEM.
I GOT 99 PROBLEMS
![Page 7: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/7.jpg)
Version Control lets you maintain a history of your files. !
This history is easily browsed, attached to author names, and logged with extra commit information. !
This is especially useful when working in a team environment.
VERSION CONTROL
![Page 8: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/8.jpg)
Git is a tool. !More specifically, it’s an open source distributed version control system with an emphasis on data integrity and speed.
GIT IS NOT GITHUB
GITgithub.com is a commercial website that allows you to host git repositories !You can use it to find many open source projects, and even share your own.
GIT HUB
You might hear these terms used interchangeably. They’re not the same!
![Page 9: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/9.jpg)
OUR FIRST repo
![Page 10: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/10.jpg)
LINGO
REPOSITORY
Local Repository - Where code is stored on your local machine !
Remote Repository - Where code is stored on a remote server (github, or internal server) !
Git stores information about the repository in a hidden .git directory contained in the same folder as the project. !
Will be commonly referred to as a repo. !
!
![Page 11: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/11.jpg)
LINGO
CLONE
Copying a github repository to your local machine.
![Page 12: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/12.jpg)
Let’s configure git on our local computer. !
Use the same email address that your github account is associated with. !$ git config --global user.name "Your Name Here” !
$ git config --global user.email "[email protected]" !
SETTING UP GIT
SET UP
![Page 13: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/13.jpg)
To set up a git repository locally, we navigate via the command line to the root of our project directory, and run the command: !$ git init
TWO WAYS TO CREATE A REPO
LOCALLY
Log in to your github account. !Next, click on the ‘plus’ icon on the right side of the toolbar, then click new repository.
ON GITHUB
You skip a few setup steps by initializing on github.
![Page 14: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/14.jpg)
GITHUB - CREATE NEW REPO
![Page 15: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/15.jpg)
CLONING OUR NEW REPOSITORY
GET THE URL
CLONE THE PROJECT LOCALLY
![Page 16: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/16.jpg)
EXERCISECREATE & CLONE A GITHUB REPO
![Page 17: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/17.jpg)
Creating a fork of my repository will copy it over to your github account.
EXERCISE
1. GO TO GITHUB.COM
Click the plus button on the right hand side, then select new repository. !Be aware, public repos are visible on the internet.
2. CREATE A NEW REPOSITORY
Copy the clone URL, then type in : !$ git clone <copied_clone_url_here>
3. COPY THE REPO URL, GIT CLONE
![Page 18: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/18.jpg)
COMMITTINGTO YOUR REPOSITORY
![Page 19: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/19.jpg)
LINGO
GIT ADD
$ git add <filename> !
Git does not automatically keep track of all the files in a project directory. !
Use git add to make it aware of a new file, or use git add on an existing file to let git know you’ve made changes to it that you want to keep.
![Page 20: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/20.jpg)
LINGO
THE STAGING AREA
When you use $ git add on a file, it gets added to the staging area. !
The staging area contains snapshots of files that will be included in the next commit.
![Page 21: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/21.jpg)
STAGING AREA
Source: http://git-scm.com/book/en/v2/Getting-Started-Git-Basics
![Page 22: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/22.jpg)
LINGO
GIT STATUS
A git command that will give you a status update about your repository. !
This is the command I use the most in my day to day git usage. !
![Page 23: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/23.jpg)
LET’S TRY IT
![Page 24: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/24.jpg)
LINGO
GIT COMMIT
Record a snapshot of the files in the staging area. !$ git commit -m “A commit message contains helpful information” !
Note: When we run a $ git status after a commit, we’ll see a message that says “nothing to commit”
![Page 25: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/25.jpg)
LINGO
GIT LOG
A way to see what changes were made, and by who. !
$ git log!
![Page 26: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/26.jpg)
Use $ git diff <filename> to show the difference between the last checked in version of that file, and the modified file.
LINGO
DIFF
![Page 27: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/27.jpg)
SIDENOTE
WHEN SHOULD I COMMIT MY CODE?
Don’t wait for your code to be a in a perfect state before committing it. !
You’ll get the best benefits by committing early & often.
![Page 28: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/28.jpg)
EXERCISECOMMIT A FILE TO OUR REPO
![Page 29: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/29.jpg)
Using the command line, navigate to the repo directory.
EXERCISE
1. NAVIGATE TO THE REPO
Open the README.md file with your editor of choice. Make and save changes.
2. MODIFY THE README
Run the command: $ git add README.md3. ADD FILE TO STAGING AREA
Run the command: $ git status to ensure your file is actually in the staging
4. RUN GIT STATUS
Run the command: $ git commit -m “my commit message”5. COMMIT YOUR CHANGES
![Page 30: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/30.jpg)
BRANCHES
![Page 31: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/31.jpg)
LINGO
MASTER BRANCH
The master branch is usually the “production ready” version of your codebase. !
That means that everything compiles, and all your tests pass. This is the version that customers will see - even if the customer is just you. !
There is only one master branch, and generally code is not committed directly to it.
![Page 32: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/32.jpg)
LINGO
FEATURE BRANCHES
Branches are extremely useful when you want to work on different features without interfering with a working copy of the code. !
When you’re done working on your feature branch, you can merge it back into master. !
If your repository is stored on a remote server, multiple developers can work on the same branch.
![Page 34: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/34.jpg)
When you create a new branch, you’re automatically switched to it. !$ git checkout -b my_branch_name
USING BRANCHES
CREATE A NEW BRANCH
$ git branch -aSEE ALL AVAILABLE BRANCHES
$ git checkout my_other_branchCHECKOUT A DIFFERENT BRANCH
![Page 35: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/35.jpg)
MERGING BRANCHES
MERGE FEATURE BRANCH INTO MASTER
Once you’re satisfied with your feature branch, it’s time to merge it back into master. !$ git checkout master !$ git merge my_feature_branch !
![Page 36: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/36.jpg)
EXERCISECREATE A FEATURE BRANCH
![Page 37: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/37.jpg)
$ git checkout -b my_new_branch
EXERCISE
1. CREATE A NEW BRANCH
Review the previous exercise if you need hints.
2. COMMIT CHANGES
3. CHECKOUT MASTER
$ git checkout master
4. MERGE YOUR BRANCH
$ git merge my_new_branch
![Page 38: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/38.jpg)
1
2
34
CREATE A BRANCH
GIT COMMIT COMMIT TO STAGING
GIT ADD ADD FILES TO STAGING AREA
WRITE CODE HACK HACK HACK
5
GIT PUSH PUSH CHANGES
UP TO REPOSITORY
GIT CHECKOUT -B
GIT WORKFLOW
![Page 39: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/39.jpg)
QUESTIOnS?
![Page 40: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/40.jpg)
COLLABORATINGWITH GITHUB
![Page 41: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/41.jpg)
LINGO
FORK
Forking a repository on github will create a copy of that project in your github account.
![Page 42: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/42.jpg)
A copy that exists in your GitHub account and can be used to submit pull requests (changes) to the maintainers of the project.
FORKING VS CLONING
FORK
A copy that does not exist in your GitHub account, and cannot change the remote repo unless the person who cloned it is added as a collaborator on the project.
CLONE
![Page 43: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/43.jpg)
LINGO
PUSH/PULL
PUSH: Send a copy of the latest committed changes to the remote server. !
PULL: Retrieve a copy of the latest committed changes from the remote server. !
Note: If you’re working on a branch with other people, always run a pull command before getting started.
![Page 44: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/44.jpg)
LINGO
PULL REQUEST
A pull request is a proposal made by you to a project maintainer asking them to accept your changes to their code base. !
The maintainer can review a diff of the changes you made. They can also leave general and code-line specific comments.
![Page 45: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/45.jpg)
FINAL EXERCISEPULL REQUESTS
https://github.com/nnja/gdi-pull-requests
![Page 46: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/46.jpg)
Creating a fork of my repository will copy it over to your github account.
FINAL EXERCISE - PT1
1. FORK MY REPOSITORY
Go to the github page of your forked copy of gdi-pull-requests. !Copy the repository URL, clone the project to your local machine.
2. CLONE YOUR FORKED REPOSITORY
https://github.com/nnja/gdi-pull-requests
git checkout -b <yourname>_branch
3. CREATE A FEATURE BRANCH
![Page 47: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/47.jpg)
Change over to the repository directory. !Create a file called <yournamehere>.txt.
FINAL EXERCISE - PT2
4. CREATE A FILE WITH A FUN FACT ABOUT YOU
git add <yourname>.txt git commit -m “here’s a fun fact about me!”
5. ADD, THEN COMMIT YOUR FILE
https://github.com/nnja/gdi-pull-requests
git push -u origin <yourname>_branch
6. PUSH YOUR BRANCH TO THE REMOTE REPO
![Page 48: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/48.jpg)
FINAL EXERCISE - PT3
7. CREATE A PULL REQUEST
https://github.com/nnja/gdi-pull-requests
![Page 49: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/49.jpg)
FIN
![Page 50: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/50.jpg)
RESOURCES!The entire Pro Git e-book. !The definitive manual. !Dense, time consuming, but chock full of information. !http://git-scm.com/book/en/v2
!Short, concise, and visual guides on beginner to advanced github topics. !https://guides.github.com/
A 15 minute interactive tutorial. Bonus: Works in your browser, no setup required. !https://try.github.io/levels/1/challenges/1
ADDITIONAL
TRY GIT PRO GIT GITHUB GUIDES
![Page 51: Nina Zakharenko - Introduction to Git - Start SLC 2015](https://reader037.fdocuments.net/reader037/viewer/2022102816/55a8617d1a28abe8628b4773/html5/thumbnails/51.jpg)
THANK YOUINTRO TO GIT
@nnja
girldevelopit.com