Upload
max-claus-nunes
View
1.114
Download
2
Embed Size (px)
DESCRIPTION
This is a short presentation about git and github. This document describes some good points to work with git and the common commands used on git.
Citation preview
Introduction to: &
Max Claus [email protected]://blog.maxcnunes.nethttps://github.com/maxcnunes
Without Version Control Systems
• Copy files into another directory• Store or Share files backups by email• Store or Share files by pendrive
Local Version Control Systems
• Just a local Database
• Systems:– RCS - Revision
Control System (Today is centralized)
http://git-scm.com
Centralized Version Control Systems
• A Central Server
• The most used for the companies
• Systems:– CVS– Subversion– TFS
http://git-scm.com
Centralized Version Control Systems
Advantages• Everyone knows to a certain degree what everyone else on
the project is doing• Administrators have more control over what everyone can
do
Disadvantages• If Server goes down, this means nobody can save changes• If HD Server breaks, this means good bye all control version
history
Distributed Version Control Systems
• Distributed: each client has fully mirror of the repository
• Systems:– Git –Mercurial– Bazaar
http://git-scm.com
Distributed Version Control Systems
Advantages• Everytime someone pulls from the central repository, Git gets a
full history of the changes• Most of the functionalities doesn’t need access to some
network. So we can work even not connected to the internet• A project can be associated to a more than one remote
repository• You can do anything just using the console
Disadvantages• Git requires some learning curve to understand its concept• The administrators don’t have control over what happens on
each client local repository
A Short History of Git
• (1991-2002) – The Linux kernel changes to the software were passed around as patches and archived files.
• (2002) – The Linux kernel project began using a proprietary DVCS system called BitKeeper.
• (2005) – The relationship between Linux kernel and the BitKeeper broke down. After that Linux development community create their own tool named Git, based on what they learned using the BitKeeper.
Some Git Goals
• Speed• Simple design• Strong support for non-linear
development (thousands of parallel branches)
• Fully distributed• Able to handle large projects like the
Linux kernel efficiently (speed and data size)
Git Basics
• Snapshots, Not Differences• Nearly Every Operation Is Local• Git Has Integrity• Git Generally Only Adds Data• The Three States
Nearly Every Operation Is Local
• You can work offline as look the history, commit some changes or create branchs
Git Has Integrity
• Git generate a SHA-1 hash for each commit associated a file
• Git realize a checksum everytime is tried to store some change. So Git knows when something was changed or the file is corrupted
24b9da6552252987aa493b52f8696cd6d3b00373
Git Generally Only Adds Data
• Doing commits regularly it is very difficult to get the system to do anything that is not undoable or lose some change
• Let us more comfortable to experiment changes, because is easy to recover a previous version
So, what are we going to do?
• Configure• Create a
Repository• Passing through
the 3 States• Branch• Merge• Log
• Alias• Diff• Tag• Ignoring Files and
Folders• Getting a Remote
Repository• Basic Workflow
Configure
• Download and Install Git: http://git-scm.com/
• You just need the Git Bash to work
git config --global user.name "Your Name Here"# Sets the default name for git to use when you commit
git config --global user.email "[email protected]"# Sets the default email for git to use when you commit
Username
Create a Repository
git init
Create the repository
cd your_folder_name
Access your project directory
git status
Check the repository current status
All your repository data and configuration is stored on a hidden folder named .git on your repository’s root
Passing through the 3 States
git commit –m ‘This is my awesome comment’
Save objects on local repository
git add (general_comand/file_name/folder_name/…)
Add objects to staging area
touch file_name/folder
Create or Change a file/folder From Nowhere/Repository Working Directory
How is the status now?
How is the status now?
How is the status now?
Working Directory Staging Area
Staging Area Repository
How is the status now?
Adding, Removing and Renaming
git add .
Stages new and modified, without deleted
git add -A
Stages All
git add -u
Stages modified and deleted, without new
git rm file_name/
Stages a removed file
git rm -r folder_name/
Stages a removed folder
git mv old_file_name new_file_name
Stages a renamed file
.gitignore
*.tmpx64/
Is a hidden file named .gitignore on your root’s repository that contains a list of all ignored files and folders, like:
Diff
git diff file_name
Compare the working directory with staging area
git diff HEAD file_name
Compare the working directory with local repository
git diff --cached file_name
Compare the index with local repository
git diff --name-status branch_1 branch_2
Compare the branchs showing just the status and file name
Custom Alias
git lol
Using the new alias
git config --global --add alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit --all"
Create a new alias to show a log with graph
git config –-local -l
List all the local configurations
Branchs
git checkout –b branch_name
Create and Switch for a new branch
git branch
List all local branchs
git checkout branch_name
Switch for a existing branch
git push remote_name branch_name
Add a local branch for a remote repository
git pull remote_name branch_name
Update local branch from a remote branch
Working with Remote Repositories
Merges
git merge branch_name
Merge on the current branch changes made on another branch
Before merge
After merge
Merge ConflictsMaster
Merge conflict
Development
Resolving the conflict
git commit –a -m ‘Resolving merge conflicts’
Commit the file after resolve the conflict
Tags
git tag
List all tags
git tag -a tag_name -m 'message description'
Creating an annotated tag
git push origin v1.0
Sharing tags
git push origin --tags
All tags
Working with Remote Repositories
git tag -a v1.0 -m 'my version 1.0'
Add and Pull a Remote Repository
git clone [email protected]:owner_repo/repo_name.git
Cloning a or repository
git remote add origin [email protected]:owner_repo/repo_name.git
git pull origin master
Actually what the clone command does is: remote add + pull
And actually what the default pull command does is: fetch + merge
Update local repository avoiding the amount of merges (fetch+rebase)git pull --rebase repo_name branch_name
Pushing to the Remote Repository
git push remote_name branch_name
Pushing for the remote repository
git push origin master
Others helpful (or not) commands
git shortlog -s -n
List of Git Contributors
git ls-files -s file_name
Show the SHA1 of a file staged
git hash-object file_name
Show the SHA1 of a file modified
git checkout --file_name
Discard changes of a file
Others helpful (or not) commands
git reset HEAD file_name
Undo git add before commit
git log --pretty=oneline
One line logs
git status -s
Short status
git reset --hard HEAD~1
Delete the last commit before Push
Look more…
• Using SSH security connections• Git Cheat Sheet Grey• http://git-scm.com