Github

Github theme

Github (Source: github.githubassets.com)

What is Github?

GitHub is a special developer platform created because it was inspired by the way programmers work. From open source to business, we can review code, manage projects, and build software with more than 56 million users worldwide.

Simply put, GitHub is a project management, version control system (VCS), as well as a social network platform for developers all over the world.

Why do we need Github?

1. Facilitate collaboration on project work

Github’s main function is to facilitate online collaboration when working on a project. With distributed version control, all developers or team members can manage code in one place. For example, conducting joint code reviews, bug fix discussions, and so on.

Apart from that, GitHub also provides a project management feature in the form of a Kanban board like Trello (more details about Kanban here. This feature is certainly very useful for those who have many projects. Because, we can more easily determine work priority, manage workflow, and see the progress of the project.

Github Portfolio

Github Portfolio (Source: docs.github.com)

2. As a portfolio for developers

Github also functions as a portfolio for developers.

Github Portfolio

Github Portfolio (Source: camo.githubusercontent.com)

On GitHub, we can set the projects we are working on to be displayed publicly. This will show our abilities as professionals.

That way, prospective clients or targeted companies can immediately see our work and contributions to various projects according to our expertise.

Create Github Account

We can create a Github account for free here. Follow the steps and we are ready to discuss more about Github.

Repository

Remote Repository

  • Local repository: Git repository stored on our computer.
  • Remote repository : Git repository stored on the server.

For our lesson now, we will put our remote repository on a Github server.

Create a repository in Github

We can create a new remote repository on our Github by:

  1. Go to the github.com page and click + drop-down menu in the top right corner, then select New repository
  2. We will be directed to the Create a new repository page, then fill in the requested information. Here’s an example:

When finished, click the Create repository button. So our Github repository has been created and is ready to be used to store projects and collaborate with our team.

Auth Github

To keep your Github account secure, we must authenticate before we can access certain resources on Github. Github has several different authentication modes, namely:

  • SSH keys
  • Personal access token
  • Username and password with two-factor authentication

Here we will learn more about authentication with SSH keys

SSH Key

SSH (Secure Shell) is a transfer protocol that allows users to control a device remote or from a distance via an internet connection securely. So we can connect to Github to access and manage our repositories without providing username and personal access token in every Git command we run.

Generate SSH key

  1. Open the Linux terminal or WSL for Windows users.

  2. Follow the commands below:

    > ssh-keygen -t ed25519 -C "[email protected]" # IMPORTANT: Replace with your email
    Generating public/private algorithm key pairs.
    Enter file in which to save the key (/home/user/.ssh/id_ed25519): # [Press enter]
    Enter passphrase (empty for no passphrase): # [Type a password]
    Enter same passphrase again: # [Type password again]

Adding your SSH key to the ssh-agent

ssh-agent is a program that manages SSH keys and remembers our password. So we don’t need to re-enter the password every time we use SSH key, just follow the steps below:

  1. Open the Linux terminal or WSL for Windows users.

  2. Follow the steps below:

    > eval "$(ssh-agent -s)" # ensure ssh-agent is running
    Agent pid 59566
    > ssh-add ~/.ssh/id_ed25519 # add our SSH key to ssh-agent
    Enter passphrase for /home/user/.ssh/id_ed25519: # [Type SSH key password]
    Identity added: /home/user/.ssh/id_ed25519 ([email protected])

Add SSH key to Github

So that Github can accept connections from our computer, we need to add the SSH key that we generated earlier to our Github account.

  1. Copy the SSH public key to the clipboard.

    > clip < ~/.ssh/id_ed25519.pub # Copy the contents of the id_ed25519.pub file to the clipboard

    Note: If clip doesn’t work, read the contents of the file with the command cat ~/.ssh/id_ed25519.pub then copy the contents of the file.

  2. In the top right corner of any page, click your profile photo, then click Settings.

  3. In the “Access” section of the sidebar, click 🔑 SSH and GPG keys.

  4. Click New SSH key or Add SSH key.

  5. In the “Title” field, add a title for the new key. This title can be filled in with the name of your device or other identification that is easy to distinguish.

  6. Paste the key that has been generated into the “Key” field.

  7. Click Add SSH key.

  8. If prompted, confirm your Github password.

Pull and Push

What are git pull and git push?

  • git pull: a command to take all commits in remote branch and merge each commit with local branch.
  • git push: a command to upload all commits in local branch to remote branch.

By default, git push and git pull only perform operations on the current branch. So, it’s best to use the git status command to see which branch we are in before doing git push or git pull.

How to Use git pull

The git pull command is:

> git pull

Example of using git pull

For example, on another computer that has the same repository, we haven’t gotten the update commit with the message “docs: add guide notes” that we push before.

> git log --oneline
71efdaa (HEAD -> main, origin/main) docs: add ideation
5dfaf0b docs: add README.md

So do git pull to get the update:

> git pull
> git log --oneline
a144815 (HEAD -> main, origin/main) docs: add guide notes
71efdaa docs: add ideation
5dfaf0b docs: add README.md

So you can see that there is an additional commit with the message “docs: add guide notes”.

How to Use git push

It is recommended to run the git pull command before starting to make changes. This will update our local branch with all new commits that other contributors may have made.

Commonly used git push commands are:

  • Push to specific remotes and branches

    > git push <remote name> <branch name>

    Example:

    > git push origin main

    We can also ensure that every time we do a push it always goes to the same remote, by running the command:

    git push -u <remote name> <branch name>

    So after we run git push with the -u option, we simply run git push without having to provide the remote and branch names again.

    Example:

    > git push -u origin main
    > git push # here we don't need to provide the remote and branch name anymore
  • Push all branches

    > git push --all

Example of using git push

Github commit before push Commits that exist in the remote repository before being pushed

> git log --oneline
a144815 (HEAD -> main) docs: add guide notes
71efdaa (origin/main) docs: add ideation
5dfaf0b docs: add README.md

We see that between the screenshot and the log above, there is one commit that is not yet in the remote (“docs: add guide notes”).

Now try executing the git push command.

> git push
> git log --oneline
a144815 (HEAD -> main, origin/main) docs: add guide notes # now this commit is in the remote repository
71efdaa docs: add ideation
5dfaf0b docs: add README.md

Github commit after push

It can be seen that our commit has been successfully push to the remote repository.

So that’s how we collaborate using remote repositories.

Clone

What is git clone?

The git clone command is used to make a copy of a particular repository from a remote repository to our local computer.

Cloning will copy the entire remote repository, including all files, commit and branch.

How to Use git clone

The way to do cloning is:

  1. On GitHub.com, navigate to the main page of the repository to be_cloned_.

  2. Above the file list, click ⤓ Code.

    Code buttons
  3. Select the SSH tab to copy the repository url and clone the repository with the SSH protocol:

  4. Open the Linux terminal or WSL on Windows.

  5. Change the current folder to where we will save the clone.

  6. Type git clone, then paste the remote URL you copied earlier and press Enter.

    > git clone [email protected]:ruang-guru/playground.git
    Cloning into `playground`...
    remote: Counting objects: 10, done.
    remote: Compressing objects: 100% (8/8), done.
    remove: Total 10 (delta 1), reused 10 (delta 1)
    Unpacking objects: 100% (10/10), done.
  7. We can see the cloned remote URL with the command git remote -v:

    > git remote -v
    origin [email protected]:ruang-guru/playground.git (fetch)
    origin [email protected]:ruang-guru/playground.git (push)
  8. Notice that we now have a clone repository located in folder playground: bash > ls playground README.md frontend introduction-to-programming ...

Now we can use the repository on the local computer and change it as needed.

Collaboration

Collaborative development models are divided into 2, namely:

  1. Fork and pull model: we do not need permission from the repository owner to push and changes are submitted by making a pull request from the fork to the original repository.

  2. Shared repository model: collaborators are given push access to one repository and branches are created when changes need to be made, pull requests are made to review changes that have been made.

Git Flow

Collaborating on Github requires us to discuss with other people every change that occurs. Usually the journey is as follows:

  • Create a branch: creates a branch so we can make changes without disturbing the flow of the main branch.
  • Make changes: commit and push changes made to branch until ready to request feedback.
  • Create a Pull Request: to request feedback from collaborators about the changes we make.
  • Address review comments: the reviewer makes questions, comments, and suggestions on the changes made and continues to commit and push in response to the review results.
  • Merge your Pull Request: after the Pull Request is approved, do merge the Pull Request that we created.
  • Delete your branch: indicates that work in branch has been completed.

Pull Request

PR (Pull Request) is a request to add changes to Github. When making homework, make a summary of the changes and issue to be solved, you can use images, links, or tables.

PR Body PR Body (source: docs.github.com)

We can also add comments to certain lines to indicate something to the reviewer.

PR comment PR comment (source: docs.github.com)

Creating a pull request

PR Review

Review is the activity of commenting on proposed changes, approving changes, or requesting changes before a PR is merged.

Review with comment Review with comment (source: docs.github.com)

Status Review

A review has three possible status, namely:

  • Comment: provide feedback without agreeing to changes or requesting additional changes.
  • Approve: provides feedback and approves the incorporation of proposed changes.
  • Request changes: provides feedback that must be addressed before changes can be merged.

PR statuses

PR statuses (source: ocs.github.com)

We can see all reviews in the Conversation timeline tab, and we can see reviews by collaborators in Pull Request’s merge box.

Conversation

Conversation (source: docs.github.com)

Review in merge box

Review in merge box (source: docs.github.com)

Resolving conversations

We can finish the conversation to show that the file has finished changing, we can click Resolve conversation in the comment bar.

Resolve button

Resolve conversation button (source: docs.github.com)

All conversations will be collapsed and marked as resolved, making it easier to find conversations that still need to be addressed.

Resolved conversation

Resolved conversation (source: docs.github.com)

Discovering and navigating conversations

We can find and navigate to all conversations using the Conversations menu displayed on the Files changed tab.

From this view, we can see which conversations are unresolved, resolved, and outdated. This makes it easier for us to find and complete conversations.

Conversation menu Conversation menu (source: docs.github.com)

Re-requesting a review

We can request a review after we make changes. To do this, on the sidebar tab Conversation, click Re-review-icon (icon).

Re-request review

For more details on how we comment on PRs we can see the documentation: Commenting on a pull request.

Organization

What is the organization in Github?

Organizations on Github are shared accounts where businesses and open-source projects collaborate with multiple projects at once. Owner and Administrator can manage member access to data and organizations with advanced security and administrative features.

Everyone who uses GitHub can use their account to create an organization. These organizations include:

  • Unlimited membership with multiple roles providing varying levels of access to the organization and its data
  • Ability to grant members various access permissions to repositories in the organization
  • Create teams to reflect a company or group structure with tiered access permissions

All organizations can have both public and private repositories.

Create an organization in Github

How to create an organization is quite easy, we can follow these steps:

  1. In the top right corner of any page, click your profile photo, then click Settings.
  2. In the “Access” section of the sidebar, click Organizations.
  3. In the “Organizations” section, click New organization.
  4. Follow the instructions to create an organization. More details can be seen at the following link: “GitHub’s products

Accessing your organization’s settings

The organization’s account settings page provides several ways to manage accounts, such as billing, team membership and repository settings.

  1. In the top right corner of GitHub.com, click your profile photo, then click Your organization.
  2. Next to the organization, click Settings.

There are more information there that can be customized for your Organization.

Back to top