Using Git on the Command Line
-
Upload
brian-richards -
Category
Software
-
view
171 -
download
4
Transcript of Using Git on the Command Line
![Page 1: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/1.jpg)
It's time to talk about Git and the importance of
source control!
![Page 2: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/2.jpg)
Imagine a scenario, if you will...
![Page 3: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/3.jpg)
You've uploaded a broken file, you don't have a working copy.
What do you do?
![Page 4: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/4.jpg)
Git to the rescue!
![Page 5: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/5.jpg)
Revert the file, upload it again, and life is great!
![Page 6: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/6.jpg)
Wow! How does Git work?
![Page 7: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/7.jpg)
![Page 8: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/8.jpg)
![Page 9: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/9.jpg)
![Page 10: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/10.jpg)
Sounds great, but how do we use Git?
![Page 11: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/11.jpg)
If you're intimidated by the command line, I recommend SourceTree:
![Page 12: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/12.jpg)
But I promise, using git on the command line is
really easy!
![Page 13: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/13.jpg)
Creating a new repository is as easy as typing:
$ git init
This adds the basic structures Git needs in order to function properly
![Page 14: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/14.jpg)
Cloning an existing repository is just as easy:
$ git clone <repo url>
This pulls down the entire git history for a given project and lets you manipulate
it as if you had created it.
![Page 15: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/15.jpg)
Adding files to your repository:
$ git add *
This will add ALL files in the current directory to your repository.
![Page 16: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/16.jpg)
Committing a set of changes:
$ git commit -m "My commit message"
This will save all staged changes to a reference point you can always restore.
![Page 17: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/17.jpg)
Checking a repository's status
$ git status
This reports which files have been modified, added, removed, etc.
![Page 18: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/18.jpg)
Un-staging some edited files:
$ git reset
This returns all staged files back to being unstaged. It does NOT undo any
edits to those files by default.
![Page 19: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/19.jpg)
Temporarily store staged edits:
$ git stash
Think of this as a way of saying, "I'm not ready to do anything with these edits,
but I don't want to erase them."
![Page 20: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/20.jpg)
Start a new "branch" for tracking edits: $ git branch mybranch
We'll use this separate branch to develop a new feature, safely isolated
from the main codebase and bug fixes.
$ git checkout -b mybranch
–or–
![Page 21: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/21.jpg)
Merge a branch back into master: $ git checkout master $ git merge mybranch
First we switch back to the master branch, then we merge in all changes
from mybranch.
![Page 22: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/22.jpg)
Pushing Edits to a remote server:
$ git push
Yep, that's really all there is to it!
![Page 23: Using Git on the Command Line](https://reader034.fdocuments.us/reader034/viewer/2022042701/55a4ede41a28ab26408b45ca/html5/thumbnails/23.jpg)
Any Questions?