GIT
Introduction to Versioning Control
What is it?
GIT allows concurrent modification of files minimising the probability of losing changes.
WHAT DOES IT DO?
Git keeps information per line of who, when and what was changed.
WHAT DOES IT ALLOW?
To know who changed something, when and why (commit message)
To get the code in a specific point in time, reverting or moving forward the changes.
HoW DOES IT?
Keeps a .git folder with information about the code and its history.
Each commit creates a "snapshot" (the state of the code at that point in time) that it's referenced with a unique identifier (hash)
concepts
State of all the files in a certain point in time.
The developer chooses when to create a snapshot.
SNAPSHOT
concepts
Current state of all the files.
Easy to check what's changed between the current code and the latest snapshot.
WORKING COPY
concepts
Creating a snapshot from the working copy is called "committing" your code.
Creates a unique identifier that can be referenced easily (commit id).
COMMIT
concepts
All code in GIT lives in a "branch".
The main branch usually is called "master".
We can have many branches.
BRANCH
concepts
A branch contains a serie of commits.
A new branch is always forked from another branch.
BRANCH
concepts
All files, branches and commits form a repository.
There's a copy in your local environment that syncs with a remote.
REPOSITORY
WORKFLOW
There are different steps to follow while working with GIT to ensure collaborative editing.
WORKFLOW
Fig 1. Standard GIT code flow.
WORKFLOW: Git add/Rm
Adds or removes files/lines to the "staging area".
New files are called "unversioned". Existing files are called "modified".
WORKFLOW: Git commit
Creates a snapshot of all the code in the local repository, with the changes in the "staging area".
Important to add a comment.
Generates a hex hash.
WORKFLOW: Git PUSH
Updates the remote repository with the changes existing in the local repository.
Makes changes available for other contributors.
WORKFLOW: Git fetch
Retrieves changes from the remote repository to get the latest code from other contributors.
WORKFLOW: Git merge
Merges code from one branch to another.
WORKFLOW: Git PULL
Alias of git fetch + git merge
WORKFLOW
Fig 2. Standard GIT snapshot/branch flow.
WORKFLOW
A branch is a serie of commits.
HEAD is a special name for the most recent commit.
Allows relative references HEAD~2
git flow
Most used branching model to work collaboratively in projects.
Awesomely explained by Vincent Driessen
git flow
Sources
https://www.slideshare.net/HubSpot/git-101-git-and-github-for-beginners
http://nvie.com/posts/a-successful-git-branching-model/
Questions
Gorka Guridi
Git
By Gorka Guridi
Git
General git explanation as introduction.
- 307