teaching-materials.org/git-oss
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Common commands:
cd
: change directory (folder)ls
: list all the filesmkdir
: make directoryrmdir
: remove/delete directorytouch
: create a filerm
: remove a filepwd
: find out the file path of current directory you are in, from the rootGit’s default text editor is vim, and you may sometimes find yourself in there accidentally.
Here are some basic commands:
i
- puts you in editor mode, so you can type the content of your file:wq
- from normal mode, saves and exits:q!
- from normal mode, exits without saving(source: xkcd)
Check for Git in your terminal:
git
Check your config:
git config --global --list
If needed, add your username and email:
git config --global user.name "YOUR_USERNAME"
git config --global user.email "github-acct-email@example.com"
You can check your config again:
git config --global --list
GitHub is an online service where people can collaborate on projects using Git.
Many open source projects have their code on GitHub.
Before we get started, make sure you have a GitHub account and have verified your email.
A repository (or “repo”) is folder for a project, with a single tracked history.
Let’s look at the repository for this website:
Go to our practice repository:
https://github.com/gdisf/git-abcsFork the main repo.
Now you have your own version on GitHub.
On your fork, click the Download or clone button.
cd
to where you want to store the repogit clone <paste-the-link-here>
ls
to see your new repocd git-abcs
to go into the repols
to see the files match the online repogit log --oneline
Compare this to the online commit history.
Check for branches in the local repo:
git branch
We’re on master
, which we want to keep the same while we work.
Checkout a new branch:
git checkout -b add-letter-x
(Replace x
with the letter you picked at the beginning of class.)
Check your branches again:
git branch
pages
folder, called letter-x.md
(replacing x
with your letter).Check the status of your repo:
git status
Git sees you’ve made a change!
Add the changed file to staging:
git add pages/<filename>
Check the status again:
git status
Commit your staged change with a commit message:
git commit -m "Add a page for letter <your-letter>"
The change is now part of the log for this branch:
git log --oneline
Your branch is now 1 commit ahead of your online fork.
Check for remote
repositories:
git remote -v
When you cloned, Git remembered the link to the repo you cloned from, and called it origin
Push your branch to origin
to see it on your fork:
git push origin your-new-branch-name
Check your repo online - it now has your branch, with your commit.
Make a pull request to propose your changes to the main repo.
Keep working on the same branch as before.
images
folder.letter-x.md
file to add the image to the page, along with a heading, using the pages/letter-b.md
file as a guide. (We’re using Markdown, because GitHub renders it as styled text in the browser. Check out their Markdown guide for more tips.)
Check your status to see what files have changed:
git status
Check the diff to see line-level changes (inside a file):
git diff
Add all changes in the current folder to staging:
git add .
Check that your changes are staged:
git status
Commit the staged changes:
git commit -m "Add image to page <your-letter>"
Check the log:
git log --oneline
Pushing commits to your branch on origin
will add the commits to your PR.
git push origin same-branch-as-before
A project maintainer will review your pull request. If everything looks good, they’ll merge it.
When a PR is merged:
First, you need to get the changes from the main repo into your local version.
Switch to your master
branch, because that’s the one we want to keep in sync:
git checkout master
Check your remote repos:
git remote -v
You’re still connected only to the fork (origin
).
Add the main repo, calling it upstream
:
git remote add upstream https://github.com/gdisf/git-abcs.git
Check your remotes again:
git remote -v
Your local repo is now connected to both remotes.
Check your branches, including remote branches:
git branch -r
Fetch the branches and history from upstream
:
git fetch upstream
Check that you can see more branches now:
git branch -r
Compare your master branch history with the upstream master:
git log --oneline master..upstream/master
This lists commits on upstream that your master doesn’t have. Merge those to your current branch (master):
git merge upstream/master
Check your log to see the new commits from upstream:
git log --oneline
Check to see there are no commits you’re missing:
git log --oneline master..upstream/master
Check your status:
git status
Your local master is now ahead of your origin (fork). Push those added commits:
git push origin master
Everything matches now!
Let’s make a new change, on a new branch, based on the updated master. First, make sure you’re still on master:
git branch
Checkout a new branch based on the current branch (master):
git checkout -b link-letter-x
(Replace x
with your same letter as before.)
Double-check you’re on your new branch:
git branch
pages/letter-a.md
as an example.)Follow the steps from before to:
Follow the steps from before to:
GitHub issues are where collaborators track bugs, propose features, and discuss changes. They are for conversation, and do not actually change code.
Anyone can open or comment on an issue.
If you find an issue you'd like to work on, avoid duplicating work by commenting to say you'll volunteer.
Feel free to ask questions if you need clarification before starting!
Use what you’ve learned to claim an issue and make a PR to fix it.
issue-8-add-m
Use what you’ve learned to fix an issue on the
teaching-materials repo.
Some tools for finding newbie-friendly projects and issues: