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
Installing Git
Mac OS X
Click here to download the latest (2.37.3) 64-bit version https://git-scm.com/download/mac
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)"
Open terminal in your launchpad or hit the 'F4' key on your keyboard and type terminal.
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.
After homebrew has finished installing type 'brew install git' into the terminal and hit 'return'
Windows
Click here to download the latest (2.37.3) 64-bit version https://git-scm.com/download/win
- Install window will pop up swiftly after downloading.
- Make sure to follow the steps as your files update.
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.
In the upper-right corner of any page, use the drop-down menu, and select New repository.
In the Repository name box, enter
hello-world
.In the Description box, write a short description.
Select Add a README file.
- 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.
Select whether your repository will be Public or Private.
Click Create repository.
Branching
Branching lets you have different versions of a repository at one time.
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
Click the Code tab of your
hello-world
repository.Click the drop-down at the top of the file list that says main.
Type a branch name,
readme-edits
, into the text box.Click Create branch: readme-edits from main.
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.
- Under the
readme-edits
branch you created, click the README.md file.
- Click the pencil to edit the file.
In the editor, write anything, maybe a bit about yourself. Try using different Markdown elements.
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
Click Commit changes.
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.
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.
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.
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.
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.
Navigate to the Files changed
tab
Red mean deletions of lines of code. Green mean code has been modified or added.
Click merge pull request under the conversations tab, then confirm because this action cannot be reversed.
You can delete any unused or fully merged branches, but keeping them as a reference for future work is common.