Skip to main content

Newbie Guide To Working On Someone's GitHub

The first thing you should do as a newbie to GitHub is install GitHub Desktop https://desktop.github.com/

Official GitHub Documentation Steps

Step 1) https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/adding-and-cloning-repositories/cloning-a-repository-from-github-to-github-desktop

Step 2) https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/making-changes-in-a-branch/managing-branches

Step 3) https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project

Step 4) https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/making-changes-in-a-branch/pushing-changes-to-github

UnOfficial Docs by Froz

1.1 Method 1: Cloning a Project from Browser

Sign in to your account at github.com and open the project owner's GitHub project in the browser. For example. https://github.com/thiendao97/HelloWorld would be one. Then clone to your  preferred location this can be any where you want. Think of it as downloading a whole folder.

1.2 Method 2: Cloning a Project from GitHub Desktop

Open GitHub Desktop. File -> Clone Repository. Paste in the project owner's project URL. Then clone to your preferred location. The default is in your Documents\GitHub.

2.1 Easily locate directory with Repository -> Show in Explorer

Major GitHub Concept - Making Changes and Discarding Changes

When you modify, add or remove files inside the GitHub project you pulled, the changes will show up on GitHub Desktop. In the video example below, I will edit hi.java and you will see changes show up.

In GitHub Desktop, if you right-click on a changed, added, or removed file you can click discard changes to revert things back to a previous commit.

Branching and working on your part of the project

To work on your portion of the project you should branch out! Give your branch a name a create it! Once you create your new branch you should press "Publish branch" to upload to the remote GitHub Repo.

You can always switch between branches on GitHub. Every time you switch branches the files and folders will change based on the branch you swapped to. The video below shows this.

After branching you can now make edits / work on your portion of the project. But before we do that lets import the project to Eclipse.

Importing the GitHub project into Eclipse

Make sure you're on the correct branch first. Then let's import!

Editing + Committing Changes

Every time you work on your branch you commit to your local repository (your computer first) and then push to origin (the repo on GitHub cloud) to upload your work.

In the video I'm on anons-branch, I made some edits to hi.java. Once I press save GitHub Desktop will notice and show you what has been changed. If you're ready to commit go ahead commit then push! If you don't know your changes and want to revert back you can always right click on the file to revert on GitHub Desktop then click on Discard changes.

Merging your branch to the main branch

Let's say you are finished with your work and are ready to merge your branch back into the main branch. To do this.... Log on to Github on the browser. Then go drop down on the branches and select all branches.

After that, press "New pull request" next to the branch you want to merge. Then you wait for the person to approve in this video example it is me. After the owner approves the pull request the branch will merge with main branch and now main branch has the new code!

 

Optional: I fucked up my commit how do I go back?

Alright these instructions aren't going to be perfect but it will help you go back to an older commit, or just check out your older commit without making any changes.

Video Part 1: Demonstrates how you can checkout and view files from an older commit

Explanation. After getting into the command line from GitHub Desktop do

git log

to show all your commits. You can use Arrow Up or Arrow Down to scroll (or PG UP, PG DOWN). Then highlight the commit number you want to checkout and right-click to copy. After that press "q" to exit the git log view.

Now type in "git checkout" and right-click again to paste the commit you copied previously.

git checkout af03dcfd00afe5d775361b5d456c43ee7f677ca9

in my example the commit number was af03dcfd00afe5d775361b5d456c43ee7f677ca9 yours may be different. Note*: Doing this brings you into "Detached Head" mode. To go back to normal and undo the checkout just switch back to "main" branch.

Now you should see that your folder has changed and went back in time! But we're not done yet we're just viewing at the moment.

After checking it out and you are sure this is the commit you want back. You have a couple of options here:

1) Revert to the older commit by goingswitching back to the main branch, then follow this doc for further details on how: https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/managing-commits/reverting-a-commit

Doing it this way preserves your whole history. "When you revert to a previous commit, the revert is also a commit. The original commit also remains in the repository's history."

2) You can make a branch based off this commit. And work on the new branch instead.

3) Completely remove all commits up to the one you checked out with (you will lose any commits newer than the commit number mentioned in git reset below) only do this if you really don't care about the newer commits.

git reset --hard af03dcfd00afe5d775361b5d456c43ee7f677ca9
git push origin