Git and Github Module
Git and Github Module
TABLE OF CONTENTS
What is git? ................................................................................................................................................... 3
What is Github? ............................................................................................................................................ 3
Getting Started with git ................................................................................................................................ 3
Confirm That You Have git ........................................................................................................................ 3
Git Installation........................................................................................................................................... 3
Configuring git ........................................................................................................................................... 3
using git/github ............................................................................................................................................. 4
Connecting git with Github ....................................................................................................................... 4
git branching ............................................................................................................................................. 4
Merging vs Rebasing ................................................................................................................................. 5
git merge ................................................................................................................................................... 5
PROS ...................................................................................................................................................... 5
CONS ..................................................................................................................................................... 5
git rebase .................................................................................................................................................. 5
PROS ...................................................................................................................................................... 5
CONS ..................................................................................................................................................... 5
Merge Conflicts ......................................................................................................................................... 5
WHAT IS GIT?
Git is a Version Control System (VCS) designed to make it easier to have multiple versions of a code base,
sometimes across multiple developers or teams. It allows you to see changes you make to your code and
easily revert them.
WHAT IS GITHUB?
Github.com is a website that hosts git repositories on a remote server. Hosting repositories on Github
facilitates the sharing of codebases among teams by providing a Graphic User Interface (GUI) to easily fork or
clone repositories to a local machine.
By pushing repositories to Github, you will pretty much automatically create your own developer portfolio as
well.
Git Installation
Git can easily be installed following this link, https://git-scm.com/downloads, and choosing a download that
fits your local machine.
Git can be used and installed on Windows, MacOS, and Linux/Unix operating software.
Configuring git
Your commits will have your name and email attached to them. To confirm that this information is correct,
run the following commands:
To fix either, just add the desired value in quotes after the command:
git branching
git branch to view current branches in repo
git checkout -b <branch name> to create a new branch with branch name
git checkout <branch name> without ‘-b’ flag to switch to existing branches
Merging vs Rebasing
From a conceptual standpoint, git merge and git rebase are used to achieve the same ultimate goal:
to integrate changes from one branch into another branch. There are, however, distinct mechanics
to both methods.
We will be discussing how to use each from the context of adding changes from your master branch
into your current working feature branch.
git merge
PROS
Generally, the easiest option to merge your master branch into your current working feature branch You can
git checkout feature and then git merge master or you could just do it with one command:
git merge feature master. By doing this, you create a new ‘merge commit’ in your feature branch,
which is a non-destructive operation that ties the histories of both branches. This preserves the exact history
of your project.
CONS
The branch that you merge will always have an extraneous merge commit that will be tracked every time you
need to incorporate upstream states. In other words, it essentially creates a forked history at the point where
you merge. This can lead to muddling the history of your branch, thereby making it more difficult for yourself
or other developers to track the history of changes using git log and/or roll back to previous states.
git rebase
PROS
To rebase, you would git checkout feature and then git rebase master. Instead of creating a
merge commit, rebase will move the entire feature branch to start from the tip of the master branch by
rewriting the project history and creating brand new commits for each commit in the original branch. The
result is a singular history with no forking of the commit history.
CONS
Because rebase rewrites project history, you lose the context provided by a merge commit, i.e. you won’t be
able to see when upstream changes were actually integrated into the feature branch. More importantly, you
could potentially cause extreme difficulty by rebasing master to the tip of your feature branch, leading git to
think that your master branch’s history has diverged from the rest. In doing so, everyone else would still be
working from the original master branch, and both masters would need to be merged.
Merge Conflicts
Merge conflicts arise when two members of the same development team work on the same file and try to
merge in their respective changes. The proper way to avoid merge conflicts would be to ensure that only one
branch is fully committed, pushed, and merged to master, allowing the other branch to integrate any changes
before attempting to push and merge to master.
If merge conflicts arise, don’t fret! Many text editors (as well as Github) provide tools to help track down
conflicts and resolve them. Often times, it will show incoming changes juxtaposed with the current state of
your file, and allow you to choose which to keep (one or both).