2. GitHub Basics
- HOW TO SET UP A GITHUB ACCOUNT AND ADD THE STUDENT DEVELOPER PACK
(WHICH GRANTS UNLIMITED FREE PRIVATE REPOSITORIES).
- SOME BASIC TERMINOLOGY
- SOME BASIC TUTORIALS ON HOW TO MANAGE GITHUB REPOSITORIES, BOTH ON THE
WEB AND WITH THE COMMAND LINE.
3. Some Terminology
Repository
A sort of "file system" with version control in which files can be uploaded to.
Local Repository
A repository that exists on a computer's (your computer's) hard drive.
Remote Repository
A repository that exists on a server's (in this case, GitHub's servers) storage.
Private Repository
A remote repository that is not browsable on GitHub.com by anyone except the
repository owner and contributors (as defined by the owner) of the repository.
Public Repository
A remote repository that is browsable on GitHub.com by anyone, but the owner or
contributors must approve commits to the repository.
4. Creating a GitHub Account and Adding
the Student Developer Pack
Go to GitHub.com
In the text boxes in the middle of the screen, enter the following
information:
Pick a username: the user name you want associated with your GitHub account,
as well as displayed with any commits you make to repositories.
Your email address: the email you want associated with your account (you can
use your YSU email, but you don't have to), also shown on commits.
Password: the password you want associated with your account.
1
6. Creating a GitHub Account and Adding
the Student Developer Pack
On the "Choose your personal plan" page, leave "Unlimited public
repositories for free" checked, click continue.
Enter information relevent to you and click next, or click "Skip this step"
2
8. Creating a GitHub Account and Adding
the Student Developer Pack
Go to https://education.github.com/pack, click "Get your pack"
Click "Yes, I'm a student"
Enter the information as it applies to you, click "Submit Request"
If you did not use your YSU email for your GitHub account, you will need to
follow the steps to add it as a contact for your GitHub account.
You should receive an email saying that your account was upgraded with
the Student Developer Pack. You can now create private repositories.
Note, this may take some time. It took a few hours for me, but can take days.
3
9. Creating a New GitHub Repository
Go to GitHub.com and sign in with your account username and password
Click "Start a Project"
Select the options you want for your repository, click "Create Repository"
You should initialize your project with a readme if creating a new repository.
The readme displays on the main page of your repository.
1
11. Creating a New GitHub Repository
After clicking create, you just made your initial commit to your repository.
Now, you can manage your repository on the Web, or using Git on the
command line.
2
12. Some Terminology (Git)
Commits
Commits are the way in which you update changes to files in your repository.
After making a change to a file, you need to commit it in order for the changes
to be reflected in your repository.
Push
Push refers to pushing committed changes from your local repository to your
server repository. IF you don't have any changes committed in your local
repository and you try to push, nothing will happen.
Pull
Pull refers to pulling changes from a remote repository to your local repository.
1
13. Some Terminology (Git)
Merge Conflicts / Conflicts
Conflicts arise when multiple commits have been made to a file which conflict
with eachother. Conflicts can be carefully resolved as to make sure the files are
in tact and correctly updated.
You probably won't have many conflicts if you are the only one working on your
repository.
2
14. Some Terminology (Git)
Branches
When you create a repository, you create one branch, the master branch. You
can create other branches to keep a separate "folder" for other code.
By convention, the Master Branch is supposed to be an always working code branch.
If you branch from Master, you get a copy of the content's of Master into the branch
you just created.
Branching is done to add new or experimental features to existing code in a way that
does not ruin the main branch of code.
Pull Requests
You can generate a pull request to pull a branch into master.
3
15. Managing a GitHub Repository (Web)
Commits on the Web
If you edit a file on GitHub.com, you can simply choose to commit and push the
file to the branch you are in at the bottom of the file editor page.
Pushing and Pulling on the Web
Depending on how you are changing files on the Web, remember, you are
working with the remote repository, so once you commit a change, your
repository is immediately updated with the change, you do not need to push in
this case.
You can create pull requests on the Web to pull branches into one another.
1
16. Managing a GitHub Repository (Web)
Adding Collaborators to a Repository
When at the main page of a repository you own, you can add collaborators
by clicking the '+' icon in the top right of the page and click "New
Collaborator"
You will then enter the username of the person's GitHub account that you want
to add.
You probably want to add Dr. Yu, his username is: fenggeorgeyu
2
17. Managing a GitHub Repository
(Command Line)
This guide assumes you are using Windows as an Operating System. Git is
available for other platforms, but the installation will differ. Once you have Git
installed, the "Using Git" section is universal.
Get Git
Go to https://git-scm.com/ and download Git for your OS (Windows was used for this
guide with Git version 2.11.0)
Pick your architecture (I recommend against the portable version unless you
know what you are doing) [64-Bit was used for this guide].
Run the installer you downloaded
"Git-2.11.0.3-64-bit.exe" was used for this guide.
You can simply leave everything as default in the installation procedure. If you
change settings, you will need to account for them later in this guide.
1
18. Managing a GitHub Repository
(Command Line)
You will notice that there are multiple programs that were installed relating
to Git: 1) Git GUI: A graphical interface for creating, cloning, and opening
repositories. 2) Git CMD: A command line (Windows) type interface for
using Git. 3) Git Bash: A Unix type interface for using Git.
Here, I will use Git Bash, but Git CMD works very similarly.
If using Linux, use one of the following commands to install Git based on
your Linux Distribution:
Debian/Ubuntu
sudo apt-get install git (or, if you are root, simply: apt-get install git)
2
19. Managing a GitHub Repository
(Command Line)
Linux Fedora
yum install git (up to Fedora 21)
dnf install git (Fedora 22 and later)
Gentoo
emerge --ask --verbose dev-vcs/git
Arch Linux
pacman -S git
openSUSE
zypper install git
3
20. Managing a GitHub Repository
(Command Line)
FreeBSD
cd /usr/ports/devel/git
make install
Solaris 9/10/11 (OpenCSW)
pkgutil -i git
Solaris 11 Express
pkg install developer/versioning/git
OpenBSD
pkg_add git
Alpine
apk add git
4
21. Managing a GitHub Repository
(Command Line): Cloning a Repo
Git Bash (Cloning a Repository)
Assuming that you created a repository online, you can now use Git to
clone your repository to your computer's hard drive.
Open Git Bash
Git Bash uses Unix (Linux, Ubuntu, etc) type commands (i.e. ls, mkdir, etc.)
On open, Git Bash will put you into your C:Users**YourUserName folder.
Create a new folder here (either with Windows Explorer or...) by typing
"mkdir 'nameOfFolder', where 'nameOfFolder' is the name of the folder you
want to create.
For this guide, I used "mkdir MyRepository"
5
22. Managing a GitHub Repository
(Command Line): Cloning a Repo
Now, we can clone a remote repository into our local repository (which will
be located in the directory we just created)
Type: "git clone {pathToRemoteRepository} ./MyRepository"
Here, {pathToRemoteRepository} will be the URL of the repository from GitHub
you want to clone, for example: https://github.com/DerekBable/CTL-Main-
Server
For this guide, I used: "git clone https://github.com/DerekBable/CTL-Main-
Server ./MyRepository/"
If necessary, you will be asked for GitHub credentials to clone the repository.
6
24. Managing a GitHub Repository
(Command Line): Cloning a Repo
Now, "cd" into the repository: "cd MyRepository"
You will notice some extra text at the end of your current line in Command Line
that says "~/MyRepository (master)"
This means your current directory is identified as a repository, and you are
currently in the master branch.
7
26. Managing a GitHub Repository
(Command Line)
While in a repository directory on your machine, you can use Git to
manage your local repository and push it to your remote repository.
8
27. Managing a GitHub Repository
(Command Line): Pull
First, it's a good idea to pull any changes made since the last time you
pulled to your local repository.
To do this, type "git pull"
If the local and remote repositories are in sync already, you will get a return of
"Already up-to-date"
9
28. Managing a GitHub Repository
(Command Line): Create/Edit Files
To create or edit files in a local repository, you can simply use File Explorer,
command line, or whatever means you wish, your local repository is
essentially the same as a normal directory on your machine.
For example, open up your repository's directory in your File Explorer and
create a new file in it.
For this guide, I created a new text document "Test.txt"
10
30. Managing a GitHub Repository
(Command Line): Adding Files
IMPORTANT: If you create a new file or folder like this, you
need to add that folder or file to Git.
To do this, type "git add fileName.ext" where fileName.ext is the file
name and extension of the file you just created.
For this guide, using the above example, "git add Test.txt"
11
31. Managing a GitHub Repository
(Command Line): Deleting Files
If you just delete a file in File Explorer, Git will not
stop tracking the file, the file will just simply be
removed from your local repostiory and not your
remote repository. To remove a file from Git and get
it to stop tracking the file (so you can actally commit
the removed file), use "git rm" instead.
For example, "git rm Test.txt"
12
Managing a GitHub Repository (Command Line): Adding
Files
32. Managing a GitHub Repository
(Command Line): Committing
After you have changed your local repository in some way
(adding, removing, or editing a file) you need to commit your
changes to the repository, then push them to the remote
repository.
To do this, make some changes to your repository (i.e. adding a file in
the above step) then type "git commit -m
{someShortMessageAboutWhatYouDid}"
The "-m" flag adds a message to your commit. It is good practice to
include a message with every commit you do.
For example, "git commit -m "Created Test.txt file."
13
33. Managing a GitHub Repository
(Command Line): Push
After commiting changes to your local repository,
you need to push those changes to the remote
repostiory.
To do this, type "git push“
Now, if you go to your repository on the web, you will see
your commited changes take effect in your remote
repository.
14
34. Important Notes
You should almost always pull before you start working with your repository.
In almost every case, you need to commit before you push (or else no changes
will be reflected).
Creating a new file in a File Explorer requires you to add the file to Git after
creation using “git add {file}”
Deleting a file in a File Explorer will not remove the file from Git, instead, use
Git Bash and use “git rm {file}”