Skip to main content

Exploring Git on GitHub

Introduction

Git enables multiple developers to work together on projects. Git is the seed that connects GitHub and your local computer across the web. This guide walks you through the Git Source Control features built into Visual Studio Code + GitHub.

Prerequisites

In order to begin this guide, you must have completed the following:

  • [Getting Started with GitHub]
  • [Vercel Setup]
  • [Visual Studio Code Setup]

What You’ll Do

  • Install Git
  • Create a Repository
  • Create a Branch
  • Make a Commit
  • Clone a Repository

Downloads

Installing Git

Mac OS X

Click here to download the latest (2.37.364-bit version https://git-scm.com/download/mac

img

Navigate to homebrew and install in your terminal if you don't already have the package manager on your operating system. Here you will copy the link...

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

img

Open terminal in your launchpad or hit the 'F4' key on your keyboard and type terminal.

img

Copy and paste the code into your terminal. You should be able to hit 'return' and run this code which will automatically download homebrew into your system. Must be on an administrator level user account.

img

After homebrew has finished installing type 'brew install git' into the terminal and hit 'return'

img


Windows

Click here to download the latest (2.37.364-bit version https://git-scm.com/download/win

  • Install window will pop up swiftly after downloading.

img

  • Make sure to follow the steps as your files update.

img

After Install

Open your VSCode application

Navigate to the Terminal tab at the top and click “New Terminal”

Type git -v or git —version in your terminal to confirm if git has been installed

$ git -v 

Type git config --global [user.name](http://user.name/) “[firstname lastname]” to set a name that is identifiable.

$ git config --global user.name "[Johnny Appleseed]"

Type git config --global user.email “[valid-email]”, preferably the email you used to set up your GitHub account this will be associated with each history marker.

$ git config --global user.email "[johnny.a@gmail.com]"

Congrats, you are finished installing Git to your computer!


Source Control on GitHub

Create a Repository

A repository is usually used to organize a single project. Repositories can contain folders and files, images, videos, spreadsheets, and data sets -- anything your project needs.

Let’s start by creating a simple  hello-world repository.

  1. In the upper-right corner of any page, use the  drop-down menu, and select New repository.

    img

  2. In the Repository name box, enter hello-world.

  3. In the Description box, write a short description.

    img

  1. Select Add a README file.

    1. Often, repositories include a README file, a file with information about your project. README files are written in the plain text Markdown language. You can use this cheat sheet to get started with Markdown syntax. GitHub lets you add a README file at the same time you create your new repository. GitHub also offers other common options such as a license file, but you do not have to select any of them now.

    img

  2. Select whether your repository will be Public or Private.

  3. Click Create repository.

    img

Branching

Branching lets you have different versions of a repository at one time.

img

By default, your repository has one branch named main that is considered to be the definitive branch. You can create additional branches off of main in your repository. This is helpful when you want to add new features, experiment, and/or make edits to a project without changing the main source of code. The work done on different branches will not show up on the main branch until you merge it, which we will cover later in this guide.

When you create a branch off the main branch, you're making a copy, or snapshot, of main as it was at that point in time. If someone else made changes to the main branch while you were working on your branch, you could pull in those updates. Think about a car switching lanes.

Create a branch

  1. Click the Code tab of your hello-world repository.

  2. Click the drop-down at the top of the file list that says main.

    img

  3. Type a branch name, readme-edits, into the text box.

  4. Click Create branch: readme-edits from main.

img

Now you have two branches, main and readme-edits. Right now, they look exactly the same. Next, you'll add changes to the new branch.

Making and committing changes

When you created a new branch in the previous step, GitHub brought you to the code page for your new readme-edits branch, which is a copy of main.

You can make and save changes to the files in your repository. On GitHub, saved changes are called commits. Each commit has an associated commit message, which is a description explaining why a particular change was made. Commit messages capture the history of your changes so that other contributors can understand what you’ve done and why.

  1. Under the readme-edits branch you created, click the README.md file.

readmebranch

  1. Click the pencil to edit the file.

img

  1. In the editor, write anything, maybe a bit about yourself. Try using different Markdown elements.

  2. In the Commit changes box, write a commit message that describes your changes.

When you do not write a message it automatically sets to Update README.md

  1. Click Commit changes.

    img

These changes will be made only to the README file on your readme-edits branch, so now this branch contains content that's different from main.

Creating your first pull request

After your changes have been saved, commited, click "hello-world" next to your name to go to the repository origin.

img

Here, you will see a message that says there have been recent pushes on the readme-edits branch and will ask you to compare and pull request.

img

When you click "create pull request," the process of merging the last changes you made on the readme-edits branch with the main branch begins. When working in a team, you can keep improving the branch as long as possible because merging to main changes how the whole application is deployed.

img

Once you've made your first pull request, you can find all pending requests in the pull request tab on the front page of the repository.

img

Select the Update README.md. 'Edit pull request'

A merge pull request event can be found under conversations. After merging,  the contents of the readme-edit branch are transferred to the main branch.

img

Navigate to the Files changed tab 

Red mean deletions of lines of code.  Green mean code has been modified or added.

img

Click merge pull request under the conversations tab, then confirm because this action cannot be reversed.

img

img

You can delete any unused or fully merged branches, but keeping them as a reference for future work is common.

img


Further Resources

Git command cheat-sheet