Lesson 2: GIT ➢ Committed means that the data is safely stored in
your local database.
Version Control
• Version control, also known as source control, is the
Repository
practice of tracking and managing changes to
software code. • A repository, or Git project, encompasses the entire
• Version control systems are software tools that help collection of files and folders associated with a
software teams manage changes to source code project, along with each file’s revision history.
over time • The file history appears as snapshots in time called
• Version control software keeps track of every commits, and the commits exist as a linked list
modification to the code in a special kind of relationship, and can be organized into multiple
database. lines of development called branches
Benefits of version control systems Getting a Git Repository
1. A complete long term change history of every file You typically obtain a Git repository in one of two ways:
2. Branching and merging
1. You can take a local directory that is currently not
3. Traceability
under version control, and turn it into a Git
Git repository, or
2. You can clone an existing Git repository from
• Git is a mature, actively maintained open-source elsewhere.
project originally developed in 2005 by Linus
• In either case, you end up with a Git repository on
Torvalds, the famous creator of the Linux operating
your local machine, ready for work.
system kernel. A staggering number of software
projects rely on Git for version control, including Basic Git commands
commercial projects as well as open source.
To use Git, developers use specific commands to copy,
Git workflow create, change, and combine code. These commands
can be executed directly from the command line or by
• You modify files in your working tree. using an application like GitHub Desktop or Git Kraken.
• You selectively stage just those changes you want to Here are some common commands for using Git:
be part of your next commit, which adds only those
changes to the staging area. • git init initializes a brand-new Git repository and
• You do a commit, which takes the files as they are in begins tracking an existing directory. It adds a
the staging area and stores that snapshot hidden subfolder within the existing directory that
permanently to your Git directory. houses the internal data structure required for
version control.
The Three States • git clone creates a local copy of a project that
Pay attention now here is the main thing to remember already exists remotely. The clone includes all the
about Git if you want the rest of your learning process project’s files, history, and branches.
to go smoothly. Git has three main states that your files • git add stages a change. Git tracks changes to a
can reside in: modified staged, and committed developer’s codebase, but it’s necessary to stage
and take a snapshot of the changes to include them
➢ Modified means that you have changed the file but in the project’s history. This command performs
have not committed it to your database yet. staging, the first part of that twostep process. Any
➢ Staged means that you have marked a modified file changes that are staged will become a part of the
in its current version to go into your next commit next snapshot and a part of the project’s history.
snapshot. Staging and committing separately gives developers
complete control over the history of their project
without changing how they code and work.
• git commit saves the snapshot to the project history • You can also specify v, which shows you the URLs
and completes the change tracking process. In that Git has stored for the shortname to be used
short, a commit functions like taking a photo. when reading and writing to that remote:
Anything that’s been staged with git add will
become a part of the snapshot with git commit.
• git status shows the status of changes as untracked,
modified, or staged.
• git branch shows the branches being worked on Branch
locally.
• git merge merges lines of development together. • Branching means you diverge from the main line of
This command is typically used to combine changes development and continue to do work without
made on two distinct branches. For example, a messing with that main line
developer would merge when they want to combine • In many VCS tools, this is a somewhat expensive
changes from a feature branch into the main branch process, often requiring you to create a new copy of
for deployment. your source code directory, which can take a long
• git pull updates the local line of development with time for large projects.
updates from its remote counterpart. Developers
use this command if a teammate has made commits
to a branch on a remote, and they would like to
reflect those changes in their local environment.
• git push updates the remote repository with any
commits made locally to a branch.
Ignoring Files
Often, you’ll have a class of files that you don’t want Git
to automatically add or even show you as being
untracked. These are generally automatically generated Git Flow
files such as log files or files produced by your build The Git Flow is the most known workflow on this list. It
system. In such cases, you can create a file listing was created by Vincent Driessen in 2010 and it is based
patterns to match them named .gitignore. in two main branches with infinite lifetime:
• The rules for the patterns you can put in the • master - this branch contains production code. All
. gitignore file are as follows: development code is merged into master in
➢ Blank lines or lines starting with # are ignored. sometime.
➢ Standard glob patterns work, and will be applied • develop - this branch contains pre-production code.
recursively throughout the entire working tree. When the features are finished then they are
➢ You can start patterns with a forward slash (/) to merged into develop.
avoid recursivity.
➢ You can end patterns with a forward slash (/) to During the development cycle, a variety of supporting
specify a directory. branches are used:
➢ You can negate a pattern by starting it with an
• feature -* - feature branches are used to develop
exclamation point (!).
new features for the upcoming releases. May
Working with Remotes branch off from develop and must merge into
develop.
• To see which remote servers you have configured, • hotfix -* - hotfix branches are necessary to act
you can run the git remote command immediately upon an undesired status of master.
May branch off from master and must merge into
master and develop.
• release -*- release branches support preparation of
a new production release. They allow many minor
bugs to be fixed and preparation of meta data for a
release. May branch off from develop and must
merge into master and develop.
Github Flow 6 principles
1. Anything in the master branch is deployable
2. To work on something new, create a branch off from
master and given a descriptively name (ie: new-
oauth2-scopes)
3. Commit to that branch locally and regularly push
your work to the same named branch on the server
4. When you need feedback or help, or you think the
branch is ready for merging, open a pull request
5. After someone else has reviewed and signed off on
the feature, you can merge it into master
6. Once it is merged and pushed to master, you can
and should deploy immediately
Lesson 2: ROUTING