A version control system (VCS) is a tool for managing a collection of program code that provides you with three important capabilities: reversibility, concurrency, and annotation.
A command line application used for software version control. It provides line-by-line change tracking and allows for simultaneous off-line editing.
Note that git does not automatically keep track of changes, you will need to manually "snapshot" different versions you wish to save.
A web service that stores git-managed projects online. You can use git to upload or download projects from GitHub.
git is the application that manages versions of your code. GitHub is just a website where those versions can be stored remotely.
# configure git to know who you are
git config --global user.email "your_email_address"
git config --global user.name "Your Full Name"
# check on command line that git is installed
git --version
repo
projectX
projectY
projectX
projectY
GitHub hosts repositories, each of which can be found at a different address.
Example: https://github.com/dpla/black-womens-suffrage(source code for https://blackwomenssuffrage.dp.la/)
You clone (download) a repository to your local machine. This creates a copy of that repo on your computer.
git clone
repo on your
machine
repo on GitHub
In order to clone repos from Github, you will need to set up an access token (like a password) for authentification. Do this under Github's Settings > Developer Settings
git clone url
git clone url
git status
Branches allow for non-linear development and for naming different versions of code in the same repo. More on this later!
main
Ada
origin
A remote is a repository on another machine that a repository can upload and download code from.
Git gives each remote a name (an "alias") to easily refer to it. By convention, the "primary" remote (where you cloned from) is named
origin
Put changes in temporary storage before committing.
git add .
git add FILENAME
use this
Store current snapshot of files in repository!
git commit -m "message"
Use informative commit messages; they document changes for others. Messages should complete the sentence:
If applied, this commit will ________________.
files
staging area
git add .
git commit -m "message"
repo
8ac18e2
a16a4f9
2f7de03
2f7de03
$ git log --oneline
2f7de03 Fourth
8417290 Third
a16a4f9 Second
8ac18e2 First
Each commit has a unique commit hash that refers to it
"First"
"Second"
"Third"
"Fourth"
HEAD
git log [--oneline]
git checkout COMMIT_HASH FILENAME
A web service that stores git-managed projects online. You can use git to upload or download projects from GitHub.
git is the application that manages versions of your code. GitHub is just a website where those versions can be stored remotely.
GitHub hosts repositories, each of which can be found at a different address.
Example: https://github.com/dpla/black-womens-suffrage(source code for https://blackwomenssuffrage.dp.la/)
Forking creates a copy of a repo on GitHub's computers, but under a different user/organization account.
info340/repo
student/repo
Assignments use a tool called GitHub Classroom to automatically create private copies (forks) of repos for assignments.
DO NOT "FORK" ASSIGNMENT REPOS
Upload commits to the GitHub cloud repo.
git push -u origin main
git push
git push
git pull
git clone url
edit files
staging area
git add
git commit
git clone
your machine
git push
your copy
follow assignment
link
Multiple people's local repositories can be linked to the same remote repository, allowing them to push and pull to the same central location.
"First"
git commit -m "First"
"Second"
"Third"
"Fourth"
git commit -m "Second"
git commit -m "Third"
git commit -m "Fourth"
Git history has been a linear sequence of commits.
HEAD
HEAD
HEAD
HEAD
Branches allow for non-linear commits.
main
main
main
main
experiment
bugfix
experiment
experiment
git branch
git branch [my_branch]
git checkout [my_branch]
git checkout -b [my_branch]
git branch -d [my_branch]
main
main
experiment
experiment
HEAD
HEAD
HEAD
HEAD
git branch experiment
git checkout experiment
git commit
git commit
git checkout main
git commit
git checkout experiment
HEAD
HEAD
experiment
HEAD
We can
merge
two branches back together, producing a commit that contains the combined changes from both branches
main
main
experiment
HEAD
HEAD
git merge [other_branch]
A merge conflict occures when two commits from different branches include different changes to the same code. Git does not know which version to keep, so makes you choose.
Merge conflicts must be resolved manually
Merge conflicts are a common and normal part of merging. They are the "typos" and "bugs" of using git.
In order to resolve a conflict, you need to edit the file (code) so that you pick which version to keep. git will add marker content where you need to make a decision:
<<<<<<< HEAD
// This is the code from the "local" version (the branch you merged INTO)
// a.k.a the version from the HEAD commit
const message = "I am an original";
const lyric = "I've got no strings to hold me down";
// There can be multiple lines that conflict, including lines being deleted
=======
// This is the code from the "remote" version (the branch you merged FROM)
const message = "I think I'm a clone now...";
// The lines need not be related in content, they've just changed in a way
// that git can't figure out which to keep!
>>>>>>> f292a3332aedc8df3e8e8cf22ca3debc214c6460
the two versions to pick from
a divider between the versions
end conflict area
git add .
git commit -m "Merge branch 'other'"
git status
to see which files have merge conflicts. Note that files may have more than one!<<<<<<<
and =======
and >>>>>>>
!!add
and commit
your changes (the code you "modified" to resolve the conflict): git pull
git fetch
then
git merge
downloads commits
The git pull command also will perform a merge; any commits from the remote "branch" will be merged into the local branch.
That means that you may need to resolve merge conflicts when pulling!
may have conflicts!
Pushing commits to Github may require merging if the commits are interwoven. Git will not allow such pushes. Instead, you need to pull changes in order to merge them, and then push the new combined/merged commits.
# attempt to push, may be blocked
git push
# IF BLOCKED, pull down the remote commits
git pull
# IF ANY CONFLICTS, resolve them!
git add .
git commit -m "Resolve merge conflict"
# now push combined commit history
git push
Because GitHub just hosts normal repositories, GitHub has branches as well! These can (but need not) correspond with the branches on your local machine.
git branch -a
git pull [remote] [branch]
git fetch
then
git merge
git fetch
Can cause conflicts!
git push [remote] [branch]
git push [remote] --all
A GitHub service that provide (free) web hosting for repository content.
The content of the gh-pages branch will be available at https://username.github.io/reponame.
To "publish" your webpage, just push your content to that branch.
# do all your coding on `main`!
# switch to gh-pages ("production" branch)
git checkout gh-pages
# merge the changes from main
git merge main
# push to GitHub to publish
git push origin gh-pages
# switch back to main branch for more coding
# DON'T FORGET THIS STEP!!
git checkout main
# remember to push your souce code
git push origin main
IMPORTANT: The gh-pages branch is your "production" branch. Never make changes on production. All changes should be made on the main branch, and then merged into production gh-pages branch.