Home Using HTML Using CSS Using JS Management Dev Environ Resources

usb Version Control & Using Github

Github is a distributed version control system that helps developers manage different versions of project files. In a distributed system, you can copy a complete repository (ie git, project) with its entire history to any machine making it easy to work remotely on projects from any physical location.

Developers utilize Git via commands that are delivered via the console which grants access to a repository. You can edit your files, then run Git commands to store your changes. Each time you complete a change to a project file, Git records a snapshot of their current contents. These snapshots are known as commits which are pushed back to the repository and stored.

This section includes a list of commands along with the circumstance that would require you to use each.

Part I: List of Git Commands and Description

Git Command
Git Description
git --help
Displays a List of Git Commands
git clone
Setup a New Repository
git init
Setup a New Repository
git status
Displays a List of File Status
git log (-p)
Displays a List of Old Commits
(Show Lines Added to each File)
git ls
Displays a List of all Repo Files
git add (.) filename.ext
Stage a File (All Files)
git commit -m (-a)
Commit a File (All Files)
git push
Synchronize Commits with Master Repo
git pull
Synchronize Commits with Team Repo
git mv
Move Files Tracked by Git
git rm
Remove Files Tracked by Git

Git Commands include 'Options' that can be specified with a Single dash (-) or a Double dash (--) followed by a Letter or a Word, respectively.

Part II: Creating a Repository

There are two ways to create a repository: You can Clone a repo from another machine, or you can Initialize a brand new repo.

[Step 1] Initialize a Repo
git init
[Step 2] Stage Files
git add filename.ext
[Step 3] Commit File Changes
git commit -m + "Description"
[Step 4] Input User Credentials
git config --global + user.email + 'your@email.address'
(One-Time Process at Start of Repo)
git config --global + user.name + 'MisterMoody'
[Step 5] Retrieve Remote Repo
git remote add origin + https://github.com/ + UserName/projectName.git

Learn more about Github AUTH Configurations.

Part III: Staging Changes

At this point, you have a repository properly configured and you simply want to save your work. Before saving your work, you run [Step 1] to ascertain what files are ready to be versioned.

[Step 1] Check Repo Status
git status
[Step 2] Stage File
git add filename.ext
[Step 3] Commit Files
git commit -m "Description"
[Step 4] Push Files to Repo
git push -u origin master

After performing these four steps, you will be promted to enter your credentials unless you use advanced features that allow you to configure your dev environment.

Part IV: Viewing File Changes

To view how a file was modified, use the git diff(--staged) to make comparisons. Files that have been modified will display - while files that have been removed will display +.

When writting commits, have fun including Emojis!

Part V: Managing Committed Files

Below are commands that may prove useful only after becoming comfortable using the console.

Remove a File
git rm filename.ext
Remove Multiple Files
git rm file1.ext file2.ext file3.ext
Rename a File
git mv "oldFilename.ext newFilname.ext"
Unstage a File
git reset HEAD^ filename.ext
Discard Recent Changes
git --checkout filename.ext
Undo Commited Changes
git log
git revert SHA ID#
(Copy & Paste the SHA ID# >> The first 5 Numbers are Required!)

The git log command produces a list of Commits along with their Simple Hashing Algorithm (SHM) identification number, which is a checksum of all changes in that commit. The checksum is the result of combining all the changes in the commit and feeding them to an algorithm that generates these 40-character strings. When you need to select a commit from your history, you can use these SHA-1 checksums, or "SHAs" for short, to identify which commit you want.

Learn more about Resets and Fixing Mistakes.

Part VI: Working with Remote Repositories

Using github for independent projects is slightly different when working with others. For starters, a repo that you own is called a Local Repo whilst a repo owned by another developer is called a Remote Repo. Each repository is a full copy of its original, including version history.

While developers can make commits to their own repo independent of others, a dev must always pull commits other developers have made from a remote repo to a local repo to maintain the most up-to-date version.

Clone a Repository
git clone + https://github.com/user/repo + newlocalFolder
Add Remote Repos
git remote add origin + https://github.ProjectURL.git
View Remote Repos
git remote (Default Remote Name is 'origin')
Update Repo / Pull Changes
git pull origin (Add Updated Files to Directory)

Collaborators typically use a declared central repository and gain acces via cloning into their local machine. This allows developers to work on different components that can be added to the central repo by pushing commits. Simply add the repo by name to the folder on your local machine.

Last Updated: 3/20/2019