season-0-ep-08-vcs
season-0-ep-08-vcs
No Version Control
2.3
File Locks
File locks allow a developer to lock a file while working on it.
e.g. SCCS and RCS
2.4
{ Hands On }
First-Time Git Setup
# check if git is installed
$ git version
# dump the git configuration and repo configuration if executed inside repo
$ git config --list
# getting help
$ git help config
3.3
When you add an untracked file, it goes directly to the staging area.
It will be added to the repository during the next commit
3 . 11
When you make a commit, staging area will flush and your files in
the working directory will be in unmodified state.
This means the files in the working directory are the same as the snapshot in the local repository
3 . 12
All the files in modified state can be added to the staging area
and will be ready to be part of the local repository during the next commit
3 . 14
Ignoring files
.gitignore
.gitignore is a file that tells git
which files in the repository should be ignored
# create file .gitignore
$ vim .gitignore
3 . 17
{ Hands On }
Ignore the rat problem in your restaurant
3 . 18
$ git status
3 . 20
{ Exercise }
Make a new commit
It's time for you to create a new commit
with both files and a nice description.
3 . 21
A piece of history
The two commits you've made are stored in your local repository
and it's possible to see them in a chronologically ordered list.
A unique key is assigned to each commit that is used as an identifier.
You'll use it whenever you want to reference a particular commit
# check your commit list
$ git log
3 . 22
{ Exercise }
Raise your prices, and commit those changes
3 . 23
Change is inevitable
Just like you have changed your prices,
a software project keeps evolving over time.
As commits store the files content at a point in time, git also
provides a tool to compare file differences across versions.
# see the differences between two commits on a particular file
$ git diff COMMIT_ID menus/bean-burrito.txt
# see the differences between two commits (every file that has changed)
$ git diff COMMIT_ID
# see the differences between the last commit and the current project state (excluding
$ git diff
# see the differences between the last commit and the current staging area
$ git diff --staged
3 . 24
{ Hands On }
Setup a Remote Repository
# Connect to the bootcamp server
ssh [email protected]
{ Hands On }
Adding Remotes
# cloning a remote
$ git clone [url]
{ Hands On }
Pulling and Pushing
# pull a copy of the master branch from the remote repository named origin,
# and merges it with the current checked out local branch
$ git pull origin master
Branches
Branch Master
Let's start simple
Let's assume this is our repository history. There's a pointer called master pointing at commit a5c3eb
That's all branches are: movable pointers.
5.3
We just created another pointer called feature pointing at the exact same commit.
5.4
Head
Now that we have two different branches pointing to the same
commit, how does Git know in which branch are we working on?
The HEAD is a special pointer that simply points to the currently checked out branch or commit.
5.5
All that happens is that HEAD is now pointing to feature instead of master
5.6
Do some work
$ touch anotherFile.txt
$ git add anotherFile.txt
$ git commit -m "working hard"
We created a new commit c57e22 and the feature pointer moved on to it.
5.7
the HEAD pointer changed to master and the state of the entire working directory
changed to what it was at a5c3eb.
5.8
A new commit 3aa2ff appeared and master moved on to it. At this point our history has diverged.
This is the whole point of branches. They enable parallel evolution of a code base.
5.9
{ Hands On }
Working with branches
# list of branches with the last commit
$ git branch -v
# delete a branch
$ git branch -d feature
5 . 10
Merging Branches
The git merge command lets you take independent branches and
integrate them into a single commit.
5 . 11
git merge
Git can merge other branches into the current branch.
The current branch will be updated to reflect the merge, but the
target branch will be completely unaffected.
This means that git merge is often used in conjunction with git
checkout for selecting the current branch and git branch -d for
deleting the obsolete target branch.
# create a branch to develop a new feature, and automatically checkout to it
$ git checkout -b new-feature
# develop a new feature..
$ git add .
$ git commit
# merge the new branch into master
$ git checkout master
$ git merge new-feature
# delete the newly merged branch
$ git branch -d new-feature
5 . 12
Conflict resolution
If two developers are working on the same file in parallel,
conflicts may arise.
When merging both commits, git is often able to automatically
resolve these conflicts based on a number of factors (e.g: date),
but sometimes the process may require human interaction.
5 . 13
{ Hands On }
Generate and solve a merge conflict