A Not-So-Brief Introduction to Github (and Github@IU)
Git basics
Git is a version control system (VCS) that is widly used.Git In Five Minutes | Everyday GIT With 20 Commands Or So | Practice with git commands
Terminologies
- Github -- the hosting site
- repo, repository -- a project database that stores the history and configuration of the project
- fork -- forking creates a new, unique repository from an existing one
- clone -- you make a copy (clone) of a remote repository in your local machine
- upstream -- after cloning a repository you often call that "original" repository "upstream".
- commit -- As a noun: A single point in the Git history; the entire history of a project is represented as a set of
interrelated commits. The word "commit" is often used by Git in the same places other revision control systems
use the words "revision" or "version". Also used as a short hand for commit object.
As a verb: The action of storing a new snapshot of the project's state in the Git history, by creating a new commit representing the current state of the index and advancing HEAD to point at the new commit.
- push -- pushing from local repository to Github hosted remote repository
- pull request -- a method of submitting contributions to an open development project. A pull request occurs when a developer asks for changes committed to an external repository to be considered for inclusion in a project’s main repository
- What to learn more--check out Git documentation:
$ git help glossary
You will act as a developer and submit your work to Github@IU
- Go to Github.iu.edu, log in using your user name;
If it is your first time to use github@IU, you are probably not yet on the organization we created for C343 (C343-Fall2019); ask an AI to add you to the organization before you continue! - Go to the organization (or use the URL https://github.iu.edu/organizations/C343-Fall2019);
- Create a repository called C343 followed by your email ID (e.g., C343yye, where yye is Prof. Ye's email ID) on github@IU, in C343-Fall2019 organization. Make sure that you select "Private" and click on "Initialize the repository with a README". Your repositiory needs to sit under the C343-Fall2019 organization;
- Check out the HTTPs clone URL of your repository; you will need this address in the following steps;
Now you need to decide how you want to use git: use the command lines (the "traditional" way) (step 5 below), or use it in Eclipse (step 6 below). - [Recommended for this course] Use EGit (git integrated in Eclipse; All git functions can be done through Eclipse).
The following procedure is based on Eclipse IDE for Java Developers Version: Mars.1 Release (4.5.1)
- Clone: Eclipse => File => Import => Git => Projects from Git => URI =>
Type in URI (https), and user and passwd for authentication =>
Branch selection (select master) => Location Destination => Import existing projects =>
Note: If Eclipse complains that there is no project in your repository to import, just click on cancel; and if the Git repository does not show up in the Eclipse window, go to Navigate => Show in => Git Repositories, then you shall see it in the Eclipse window. - Now you have a clone of the repository on your local machine
- Try to create a project (HelloWorld) under lab1:
File => New => Java Project (type in HelloWorld for project name, select lab1 in your repository for location)
- Create a class in this project:
File => New => Class - When you are done with the code, you need to push it upstream:
The Git Staging view provides a convenient compact overview on all changes you have done compared to the current HEAD revision.
Open the Git Staging view via the Window -> Show View -> Other... -> Git -> Git Staging menu.
In this view you select all files which have changed and drag them into the Staged Changes area. To commit the staged changes you write a descriptive commit message and press the Commit button; or you can press the Commit and Push button to commit and push the commit to upstream.
- Clone: Eclipse => File => Import => Git => Projects from Git => URI =>
- Use git in command lines [basic unix/linux commands]:
You will use the following command lines on a linux/unix machine, or Mac terminal.
If you use a Windows machine, use PuTTY to connect to burrow.soic.indiana.edu (a linux machine); you may also try Gitbash (https://git-for-windows.github.io/), and then work with git like you will work in the Mac terminal or a linux machine.- Make a copy of the repository on your local machine:
git clone https://github.iu.edu/C343-Fall2019/C343yye.git (replacing 'yye' by your IU user name);
you will be asked to provide your account & password. After you provide the information, you now should have a copy of your repository (named C343...) on the "local" machine. - You are now ready to make changes to your local copy (E.g., you write a code Hello.java under lab1 folder);
You can use any of the editors (vim, Emacs or pico) to write your code. [vim cheat sheet; Emacs cheat sheet; pico] - Not done yet--you need to upload the changes to github as follows;
(under your local folder, e.g., ~/C343yye/)
git add .
git commit -m "whatever meaningful message"
git push
(to remove a file/folder? e.g, git rm -r folder1, followed by git commit & git push) - Now your changes should be propagated to your repository on Github@IU;
- Make a copy of the repository on your local machine:
- Other options:
- Use git with GUI: look for "Clone in Desktop" on github.
- If you really cannot get any of these work, you may create folders/files directly on github. Go to the destination folder in your repository (e.g., week2) and look for the "+" sign to create a new file (and a folder), as shown below.
- Use git with GUI: look for "Clone in Desktop" on github.