introduction into git

Post on 15-Apr-2017

373 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Introduction into Git

Serhii KartashovDecember 2015SoftjournInternship

Agenda

Fundamental Concepts of VCS

Git

Development Model

Advanced Tips

Agenda

Fundamental Concepts of VCS

Git

Development Model

Advanced Tips

Types of Version Control Systems (VCS)

Distributed Version ControlCentralized Version Control

server

client client

repo

repo repo

Fundamental Concepts• repository • working copy• conflicts• merging changes• development (branching) model

tag dev feature

origingit repo

git repo git repo

commit

branch

repo

git repo git repo

Agenda

Fundamental Concepts of VCS

Git

Development Model

Advanced Tips

How to start working with Git• Install Git client (see useful links at the end)

– git --version• Config you client

– git config --global user.name “Serhii Kartashov“– git config --global user.email Serhii.Kartashov@example.com– git config --list (check your settings)

• Clone a branch from a repository– git clone https://myrepo.com/repo workdir

• Initialize your local repo and link to remote repo– git init– git remote add <my_fork> <url>

• Use git help command– git help clone (launches browser to display HTML with instructions on how to use this

clone command)• You may add .gitignore file to ignore some files, i.e. <*.jar>

Life cycle of files in your repo

Saving Changes

• Adding files to stage area:– git add <file>– git add <directory>– git add --all

• Commit the staged snapshot to the project history:– git commit -m “<message>”– git commit –a (will open text editor - vi)

Inspecting a Repository

• Display a status of working directory and the staging are:– git status

• Display committed snapshots:– git log– git log --oneline– git log -p <file>– git log --stat – git log –graph --decorate –oneline– git log –author=“Serhii Kartashov”

Undoing Changes. revert

• Undo a committed snapshot. – git revert <commit>

But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content.

Undoing Changes, reset

• edit two files, stage one• run git reset HEAD to undo the stage• re-stage the file and commit• run git reset --soft HEAD~ to undo the commit but

keep the staged files; commit again• run git reset HEAD~ to undo the commit and all

staging; commit again• run git reset --hard HEAD~ to lose the commit and

all that work

Undoing Changes, clean

• Remove untracked files from your working directory– git clean –n (just shows you what may be

removed)– git clean -f (files only)– git clean –df (files and directories)

Rewriting history

The git commit --amend command is a convenient way to fix up the most recent commit. It lets you combine staged changes with the previous commit instead of committing it as an entirely new snapshot.

Rewriting history, rebase

• Rebasing is the process of moving a branch to a new base commit. – git rebase <base>

Agenda

Fundamental Concepts of VCS

Git

Development Model

Advanced Tips

Development (branching) model

• Branch convention: – master– develop– release-* (tags)– hotfix-*

Using Branches, branch

The git branch command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again.– git branch (list branches)– git branch <branch> (create new branch)– git branch -d <branch> (delete the specified branch)– git branch -m <branch> (rename the current branch

to <branch>)

Using branches, checkout

The git checkout command lets you navigate between the branches created by git branch.– git checkout <existing-branch>– git checkout -b <new-branch>

Using Branches, merge

The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.– git merge <branch>– git merge --no-ff <branch> (merge the specified

branch into the current branch, but always generate a merge commit)

Git Work Flow Cycle

clone repo create,

checkout branch

make changes

update branchadd files

to stage

commit staged

files

push commits

to repo/fork

create pull

request

Clone repository• git clone• git init• git remoteCreate/Checkout branch• git branch• git checkoutMake changes• git add• git resetUpdate branch• git diff• git fetch• git rebaseCommit changes• git commitPush changes to repo• git push

Agenda

Fundamental Concepts of VCS

Git

Development Model

Advanced Tips

Stashing

• Stash the changes in a dirty working directory away – git stash– git stash list – git stash apply– git stash show <stash_name>– git stash drop <stash_name>– git stash branch testchanges– git stash clear

Filtering and Formatting Logs

• git shortlog• git log --graph --oneline --decorate• git log -3 (display only the 3 most recent

commits)• git log --after="2014-7-1“ (by date)• git log --author="John\|Mary“• git log --grep="JRA-228:“ (by name)• git log -S"Hello, World!" (by content)

Useful links• Git clients

– http://git-scm.com/downloads (required)– https://code.google.com/p/tortoisegit/wiki/Download

• Useful Git resources– https://www.atlassian.com/git/tutorials/setting-up-a-repository/#!

overview – http://ndpsoftware.com/git-cheatsheet.html#loc=workspace – https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf – Squash several Git commits into a single commit

• Git books and docs– http://git-scm.com/book– Command’s list http://git-scm.com/docs – http://git-scm.com/documentation

Home Work. Git1. Work Cycle:

1. create and init remote repository (set-url);2. checkout branch and create new one;3. rename branch;4. create new files and add it to git;5. commit changes and push them to remote repo;6. use reset command (stage, commit, etc.)7. use stash command (list, drop, save, pop, branch)

2. Branches: 8. copy new branch from created before (task 1);9. apply changes in new branch and commit it (create possible conflict

between them);10. merge changes in the second branch into first one.

top related