0% found this document useful (0 votes)
25 views46 pages

GitHub Tutorial

The document provides a visual guide to using GitHub for collaborating on projects. It shows that users fork a parent repository to create their own copy, then clone it to their local computer and pull updates from the parent. They can make changes locally, add them to git, and check the status before pushing updates to their forked repository on GitHub.

Uploaded by

Muhammad Wahaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views46 pages

GitHub Tutorial

The document provides a visual guide to using GitHub for collaborating on projects. It shows that users fork a parent repository to create their own copy, then clone it to their local computer and pull updates from the parent. They can make changes locally, add them to git, and check the status before pushing updates to their forked repository on GitHub.

Uploaded by

Muhammad Wahaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Introduction to GitHub tutorial:

A basic visual guide

Stephanie N. DeCross
Harvard University, Department of Psychology
[email protected] | https://github.com/sdecross

https://doi.org/10.5281/zenodo.3369466
How do I use GitHub to collaborate on a project?
Local computer The cloud
GitHub: Parent Repo
https://github.com/impt-
person/group-project

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3a Work on file
mycode.R GitHub: Parent Repo
and save https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save https://github.com/impt-
person/group-project

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
group-project$
git commit 1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
group-project$
git commit 1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
group-project$
git commit 1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop
~/Desktop/group-project

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
group-project$
git commit 1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop 4 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

2 Clone (first time)


GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
group-project$
git commit 1 First time: fork

(GitHub concept –
button on GitHub!)
My Laptop 4 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

origin
2 Clone (first time)
GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
5 Pull
group-project$
git commit request 1 First time: fork

(GitHub concept –
button on GitHub!)
(GitHub concept –
button on GitHub!)
My Laptop 4 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

origin
2 Clone (first time)
GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
5 Pull
group-project$
git commit request 1 First time: fork

(GitHub concept –
button on GitHub!)
(GitHub concept –
button on GitHub!)
My Laptop 4 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project ~/group-project$
git push

origin
2 Clone (first time)
GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

If you have direct write access to the parent repo, you can push
3d Commit
directly to upstream (it doesn’t require permission, like a pull 5 Pull
~/group-project$
request). This would take the place of step 5.
git commit request 1 First time: fork

~/Desktop$ git push upstream master (GitHub concept –


button on GitHub!)
(GitHub concept –
button on GitHub!)
My Laptop 4 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

origin
2 Clone (first time)
GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


What if someone makes changes to the parent repo?
How do I get the latest version?
3b Add file to git
3a Work on file
group-project$
git add mycode.R
mycode.R GitHub: Parent Repo
and save 3c Check status https://github.com/impt-
person/group-project
group-project$
git status

3d Commit
5 Pull
group-project$
git commit request 1 First time: fork

(GitHub concept –
button on GitHub!)
(GitHub concept –
button on GitHub!)
My Laptop 4 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

origin
2 Clone (first time)
GitHub: My Repo
~/Desktop$ git clone
https://github.com/impt-
https://github.com/me/group-project
person/group-project.git

Thereafter, pull
~/Desktop$ git pull

Local computer The cloud


GitHub: Parent Repo
https://github.com/impt-
person/group-project

My Laptop
~/Desktop/group-project

origin

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


Get updates GitHub: Parent Repo

from parent repo https://github.com/impt-


person/group-project

My Laptop
~/Desktop/group-project

origin

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


Get updates upstream

GitHub: Parent Repo

from parent repo https://github.com/impt-


person/group-project

My Laptop
~/Desktop/group-project

origin

GitHub: My Repo
https://github.com/me/group-project

Local computer The cloud


Get updates upstream

GitHub: Parent Repo

from parent repo https://github.com/impt-


person/group-project

My Laptop
~/Desktop/group-project

origin

GitHub: My Repo
Link the parent repo to your local (Only need
1 https://github.com/me/group-project
project and check that it connected to do once!)

group-project$ git remote add upstream


https://github.com/impt-person/group-
project.git
group-project$ git remote -v

Local computer The cloud


Get updates 2 Pull from parent repo to upstream
local project
group-project$ git pull GitHub: Parent Repo

from parent repo


upstream master
https://github.com/impt-
(This doesn’t update person/group-project
My Repo though!)

My Laptop
~/Desktop/group-project

origin

GitHub: My Repo
Link the parent repo to your local (Only need
1 https://github.com/me/group-project
project and check that it connected to do once!)

group-project$ git remote add upstream


https://github.com/impt-person/group-
project.git
group-project$ git remote -v

Local computer The cloud


Get updates 2 Pull from parent repo to upstream
local project
group-project$ git pull GitHub: Parent Repo

from parent repo


upstream master
https://github.com/impt-
(This doesn’t update person/group-project
My Repo though!)

My Laptop 3 Push to origin by(Mydefault!)


Repo

~/Desktop/group-project group-project$
git push

origin

GitHub: My Repo
Link the parent repo to your local (Only need
1 https://github.com/me/group-project
project and check that it connected to do once!)

group-project$ git remote add upstream


https://github.com/impt-person/group-
project.git
group-project$ git remote -v

Local computer The cloud


Get updates 2 Pull from parent repo to upstream
local project
group-project$ git pull GitHub: Parent Repo

from parent repo


upstream master
https://github.com/impt-
(This doesn’t update person/group-project
My Repo though!)

Parent repo, local project, and my


repo are now all updated.
My Laptop 3 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

origin

GitHub: My Repo
Link the parent repo to your local (Only need
1 https://github.com/me/group-project
project and check that it connected to do once!)

group-project$ git remote add upstream


https://github.com/impt-person/group-
project.git
group-project$ git remote -v

Local computer The cloud


Get updates 2 Pull from parent repo to upstream
local project
group-project$ git pull GitHub: Parent Repo

from parent repo


upstream master
https://github.com/impt-
(This doesn’t update person/group-project
My Repo though!)

Parent repo, local project, and my


repo are now all updated.
My Laptop 3 Push to origin by(Mydefault!)
Repo

~/Desktop/group-project group-project$
git push

origin

GitHub: My Repo
Link the parent repo to your local (Only need
1 https://github.com/me/group-project
project and check that it connected to do once!)

group-project$ git remote add upstream


https://github.com/impt-person/group- Pull from parent repo & push to origin (steps 2-3)
project.git
group-project$ git remote -v
at least once a day to stay updated!

Local computer The cloud


How do I get my folder on my computer onto GitHub?
(How do I go the other way
and go FROM my computer TO GitHub?)
(Directory to be git-ified)

My Laptop
~/Desktop/my-project
GitHub: My Account

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

On GitHub, click the plus


1
button to add an empty new
repository, name it, and note
the URL.

My Laptop
~/Desktop/my-project GitHub: My Repo
https://github.com/me/repo-project

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

On GitHub, click the plus


1
button to add an empty new
repository, name it, and note
the URL.

My Laptop
~/Desktop/repo-project

My Laptop
~/Desktop/my-project GitHub: My Repo
2 Clone repo to desktop https://github.com/me/repo-project
~/Desktop$ git clone https://github.com/me/repo-project.git

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

3 Drag-and-drop (or $ mv) contents of my- On GitHub, click the plus


project into repo-project. Repo-project is 1
button to add an empty new
already initialized and already has the origin repository, name it, and note
linked, since it was cloned. the URL.

My Laptop
~/Desktop/repo-project

My Laptop
~/Desktop/my-project GitHub: My Repo
2 Clone repo to desktop https://github.com/me/repo-project
~/Desktop$ git clone https://github.com/me/repo-project.git

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

3 Drag-and-drop (or $ mv) contents of my- On GitHub, click the plus


project into repo-project. Repo-project is 1
button to add an empty new
already initialized and already has the origin repository, name it, and note
linked, since it was cloned. the URL.

4 Add and commit the contents.


~/Desktop/repo-project$ git add .
My Laptop ~/Desktop/repo-project$ git commit -m “First commit”

~/Desktop/repo-project

My Laptop
~/Desktop/my-project GitHub: My Repo
2 Clone repo to desktop https://github.com/me/repo-project
~/Desktop$ git clone https://github.com/me/repo-project.git

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

3 Drag-and-drop (or $ mv) contents of my- On GitHub, click the plus


project into repo-project. Repo-project is 1
button to add an empty new
already initialized and already has the origin repository, name it, and note
linked, since it was cloned. the URL.

4 Add and commit the contents.


~/Desktop/repo-project$ git add .
My Laptop ~/Desktop/repo-project$ git commit -m “First commit”

~/Desktop/repo-project
5 Push to the origin
~/Desktop/repo-project$ git push
My Laptop
~/Desktop/my-project GitHub: My Repo
2 Clone repo to desktop https://github.com/me/repo-project
~/Desktop$ git clone https://github.com/me/repo-project.git

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

3 Drag-and-drop (or $ mv) contents of my- On GitHub, click the plus


project into repo-project. Repo-project is 1
button to add an empty new
already initialized and already has the origin repository, name it, and note
linked, since it was cloned. the URL.

4 Add and commit the contents.


~/Desktop/repo-project$ git add .
My Laptop ~/Desktop/repo-project$ git commit -m “First commit”

~/Desktop/repo-project
5 Push to the origin
~/Desktop/repo-project$ git push
My Laptop
~/Desktop/my-project GitHub: My Repo
2 Clone repo to desktop https://github.com/me/repo-project

You can delete the ~/Desktop$ git clone https://github.com/me/repo-project.git

empty “my-project”
locally. Work more
locally (in repo-project)
and save file, then
repeat steps 4-5.
Rinse & repeat. FROM my computer TO GitHub
Local computer The cloud
How do I get my folder on my computer onto GitHub?
(How do I go the other way
and go FROM my computer TO GitHub?)
… another way.
(Directory to be git-ified)

My Laptop
GitHub: My Account
~/Desktop/my-project

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)

On GitHub, click the plus


1
button to add an empty new
repository, name it, and note
the URL.

My Laptop GitHub: My Repo


~/Desktop/my-project https://github.com/me/my-project

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)
Initialize the directory, add it, and commit On GitHub, click the plus
2 1
it. Then add the origin with the URL. button to add an empty new
Check that it’s been added. (Only need to init, add origin,
and verify origin once!) repository, name it, and note
~/Desktop$ cd my-project the URL.
~/Desktop/my-project$ git init
~/Desktop/my-project$ git add .
~/Desktop/my-project$ git commit -m “First commit”
~/Desktop/my-project$ git remote add origin
https://github.com/me/my-project.git
~/Desktop/my-project$ git remote -v

origin

My Laptop GitHub: My Repo


~/Desktop/my-project https://github.com/me/my-project

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)
Initialize the directory, add it, and commit On GitHub, click the plus
2 1
it. Then add the origin with the URL. button to add an empty new
Check that it’s been added. (Only need to init, add origin,
and verify origin once!) repository, name it, and note
~/Desktop$ cd my-project the URL.
~/Desktop/my-project$ git init
~/Desktop/my-project$ git add .
~/Desktop/my-project$ git commit -m “First commit”
~/Desktop/my-project$ git remote add origin
https://github.com/me/my-project.git
~/Desktop/my-project$ git remote -v

origin

My Laptop GitHub: My Repo


~/Desktop/my-project https://github.com/me/my-project

3 Push to the origin


~/Desktop/my-project$ git push origin master

FROM my computer TO GitHub


Local computer The cloud
(Directory to be git-ified)
Initialize the directory, add it, and commit On GitHub, click the plus
2 1
it. Then add the origin with the URL. button to add an empty new
Check that it’s been added. (Only need to init, add origin,
and verify origin once!) repository, name it, and note
~/Desktop$ cd my-project the URL.
~/Desktop/my-project$ git init
~/Desktop/my-project$ git add .
~/Desktop/my-project$ git commit -m “First commit”
~/Desktop/my-project$ git remote add origin
https://github.com/me/my-project.git
~/Desktop/my-project$ git remote -v

Work more locally and save file, then repeat


yellow lines only in step 2 to add and origin
commit, then repeat yellow part of step 3.
My Laptop Rinse & repeat. GitHub: My Repo
~/Desktop/my-project https://github.com/me/my-project

3 Push to the origin


~/Desktop/my-project$ git push origin master

FROM my computer TO GitHub


Local computer The cloud

You might also like