Girl Develop It | Summer 2018
Find these slides at https://github.com/ShaynaCummings/gdi-intro-github
Girl Develop It exists to provide affordable and judgment-free opportunities for women interested in learning web and software development.
Thank you to our wonderful TAs!
Instructor:
@ShaynaCummings
shayna.cummings@gmail.com
We'll be using the following tools in class today:
Ever worked on a group paper and ended up with something like this?
Version history in Google Docs
Software that allows you (and your team) to do two powerful things:
Collaborate: Create anything with other people, from academic papers to entire websites and applications.
Track and revert changes: Ability to see who specifically made what changes and when. Be able to go back to a "snapshot in time" to fix something that went wrong.
There is one central server and each client (person) checks out and commits changes to it
Each client (person) has a local copy of the code, which they can then reconcile with the main server.
Git: Free, open source version control system
GitHub: web-based service that interacts with Git and allows you to host and share your code for free. You can:
git initto make it a Git repo (or
git clonean existing repo)
git addchanges to the Index (staging area) as you work
git commitchanges to the Head ("official" list of changes)
git pushchanges to your remote repository
user@bash:
git --version
In order to record changes in your commit history, Git needs to know a little about you.
Add your Github Username
git config --global user.name "YOUR NAME"
And the email attached to your GitHub account
git config --global user.email "YOUR EMAIL"
1. Create new folder
mkdir my-repo
2. Switch into that folder
cd my-repo
3. Initialize the folder as a Git repo
git init
Let's check it out!
ls -al
Hey, there's a new (hidden) folder:
your-name staff 128 Jun 19 00:23 .
your-name staff 672 Jun 19 00:39 ..
your-name staff 384 Jun 19 01:04 .git
Let's see what's inside
ls -al .git
We can also look at this Finder, but you'll only see .git if hidden files are set to visible
Create a new file
touch README.md
Every repository should have a README file!
git status: Check to see what changes Git has noticed
git status
git add: Adds files to the Index (staging area for your next commit)
Add all changed files
git add -A
Or to add a single file
git add README.md
git add-ed something you didn't intend to?
git resetremoves those file changes from the Index
Remove all files (from the Index)
git reset
Remove a single file (from the Index)
git reset README.md
git commit: Commits your changes to the Head
git commit -m "Update README file"
git log: Shows list of commits
git log
commit 0ac0ce458f65958fd6 (HEAD -> master)
Author: Shayna Cummings
Date: Tue Jun 19 01:14:20 2018 -0400 Add README file
git reset [commit]: undoes all commits after [commit] (but keeps all commits in log history)
git reset 579e546a022fe0e1297d80ebefa4c
--hardoption discards log history
git reset --hard 579e546a022fe0e1297d80ebefa4c
In every repo, there are likely some files that you don't want Git to track, including:
You can tell Git to ignore any changes to these files by listing them in a .gitignore file. Templates for many languages are available at github.com/github/gitignore
Create a .gitignore file inside your repo
cd my-repo
vim .gitignore
Add paths for files you want Git to ignore
.DS_Store
*.log
~
~
--INSERT--
Why use a remote repository?
Find the URL for your new GitHub repo
git remote add origin https://github.com/...
Verify that the remote repo was added
git remote -v
git push [remote name] [branch name]
git push -u origin master
Git & GitHub allow users to work collaboratively on the same project through:
See what branch you're currently on
git branch
git checkout -b [branchname]: creates new branch
git checkout -b add-widgets
Use a descriptive branch name, so you'll remember what you did on it.
git push [remote] [branchname]:
git push origin add-widgets
[first name][last initial]
, for example: shaynac
[first name][last initial].txt
, for example: shaynac.txt
git clone [URL]
git clone https://github.com/gdiboston/gdi-intro-github-students
https://github.com/gdiboston/gdi-intro-github-students
Click the 'Fork' button to make a copy of someone else's repo on your own Github account, and then use 'git clone' to clone your copy to your local computer
git clone [URL]
git clone https://github.com/YOURUSERNAME/gdi-intro-github-students
Pull requests (PRs) send a message to the owner(s) of the repo asking to merge your branch with your changes into the master branch
Switch to your branch and click 'new pull request'
You can open a PR from your branch -> master within one repository
OR
from your branch in a forked version of a repo -> the original repository
If there are no conflicts, a pull request can be merged with one click
Depending on the repo settings, you may be able to merge your own pull requests... this is not always a good idea
After pull requests are merged, it's important you sync up your local repo!
git pull [remote]:
git checkout master
git pull origin
Merge conflicts occur when changes in your branch conflict with changes made to the remote master.
This can happen when:
1. Sync your local master with the remote master
git checkout master
git pull
2. Attempt to merge your local master into your local working branch (Git will tell you there's a conflict)
git checkout problem-branch
git merge master
3. Edit the problem file(s) in your local branch to remove the conflict(s) with the master branch. Git will mark conflicts in your files using <<< and >>>
<<<<<< HEAD Here's the line in your branch ====== Here's the same line in the master >>>>>> master
4. Commit your changes
git add [files]
git commit -m "resolve merge conflict"
5. Push your changes to the remote branch
git push origin problem-branch
No need to open a new Pull Request - your pushed changes will automatically be reflected in the current Pull Request
Questions?
boston@girldevelopit.com