Getting Started with GIT
Basic Navigation
• cd means change directory• cd .. moves you up a level• cd dir_name moves you to the folder named
dir_name• A dot (.) refers to the current directory• ls displays directory contents
Create a Project from Scratch
git init project creates a project directorygit add adds files to the directorygit commit –m"message" commits the changes
$ cd projects$ git init project1
*** create file1.txt ***
$ cd project1$ git add file1.txt$ git commit -m "Committing project 1"
Create a projects directory on ned in 216
Create a Project from an Existing Directory
git init . initializes the current directorygit add * adds all files in the directorygit commit –m"message" commits the changes
$ cd ../projects/project2$ git init .$ git add *$ git commit -m "Committing project 2"
Create a projects/project2 directory, and create a file in that directory called file2.txt
View your Commit Logs
git log displays your log history
Check your Status
git status displays the status of the repoIn the projects/project2 directory, modify file2.txt and create a file called file3.txt
modified file
new file
Update your repo
add the file
commit the changes
check the status
Try It
• Navigate to the projects directory• Initialize project3• Create file4.txt in the directory
– Add file4 to the repo– View Git status– Commit the change
• Modify file4– View Git status– Commit the change
• Create file5.txt in project3– View Git status– Add it to the repo– Commit the change
Access a Git Project from GitHub
• Most open source projects have a read-only Git URL• Visit github.com Explore• git clone https://... copies repository content to your
system
Access a Git project
URL -- https://github.com/garrick/git-for-one-presentation.git
Create a new folder from the command line
Change to the new folder
Pull down a copy of a github project
Display directory contents
Right click here to Edit Paste,
or press the Insert key on the keyboard
Keep Current
• git pull will bring down latest content• If you've made conflicting changes, this may
not work easily• You can always delete the directory contents
and pull down a fresh copy
Pick a Plan
With a free account, all repos are public.
Create a Repository on GitHub
Set up the Repository
Set up your GitHub "origin"
Copy the URL from GitHub
In Bash: $git remote add origin https://...Paste URL
You can paste by right clicking
Push to GitHub$git push -u origin master
Copies your project to GitHub
Enter your credentialsYou should only have to do this once!
"Origin" is GitHub
"Master" is local copy
Voila!
Add a ReadMe
Pull the ReadMe into your Local copy
Copy URL from GitHub
In Bash: $ git pull URL
Try It
• Create a GitHub repo for Project1• Push your local copy to the repo• Add a ReadMe file in GitHub• Pull the ReadMe to your local copy• Modify file1.txt in Project1• Add a new file to Project1• Commit your changes (don't forget to add the new
file to the repo first!)• Push your changes to GitHub
Deleting a Repo from GitHub
• Select the Repository• Click Settings• Click "Delete this repository "under Danger
Zone– This cannot be undone!
• Type the name of the repository to confirm
Git for Windows
Download Git Install GitUse default options
Open Git Bash
Configure Git
Configure usernameConfigure password
Everything elseis just the same!
This creates two key-value pairs, used for tracking commits.
$ git config --global user.name "Joe Shmo"$ git config --global user.email "[email protected]"
Store your Credentials
• Download Windows Credential Store for Git• Run It!• Click Yes
Summary• Check status
• git status• Add a remote location to
upload files• git remote add origin url
• Push changes from local to remote• git push -u origin master
• Pull changes from remote to local• git pull url
• Initialize a project• git init projectName• git init .
• Add a file• git add fileName• git add *
• Commit changes• git commit -m "remark"
• View the log• git log
Git Isn't Just for Code
• You can commit anything to a Git repository– Pictures– Word docs– PowerPoint presentations– Videos– Music– etc.
Learn More
• GitGuys• Git Documentation• Git Cheat Sheet