0% found this document useful (0 votes)
8 views47 pages

Git B en Vs PDF

Git is a distributed version control system created by Linus Torvalds in 2005 for Linux kernel development. It allows users to manage changes in source code, create branches for feature development, and merge changes efficiently. The document outlines Git's core functionalities, including committing changes, branching, merging, rebasing, and managing remote repositories.

Uploaded by

yakubovajamila97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views47 pages

Git B en Vs PDF

Git is a distributed version control system created by Linus Torvalds in 2005 for Linux kernel development. It allows users to manage changes in source code, create branches for feature development, and merge changes efficiently. The document outlines Git's core functionalities, including committing changes, branching, merging, rebasing, and managing remote repositories.

Uploaded by

yakubovajamila97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Git

Versions control system (VCS)


SVN Git
Do changes
Request exact version
Local Changed
Copy Copy

Calculate the Client


Client Client
di erence
Fetch remote
Store the storage
di erence
Server
Server

Do changes
Client Client
Client
Client

Client Update remote


storage

Git - distributed version control system


ff
ff
Git
Git was originally authored by Linus
Torvalds in 2005 for development of the
Linux kernel

• Git is a connected, directed graph


without cycles
• Graph vertices can have labels

3
Commit
---------------------------------
Repository (git database)
/\
-------------------------------- || $ git commit -m «done!»

Staging area («index»)


/\
-------------------------------- || $ git add file.ext

Working copy
----------------------------

4
Commit
Commit
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]

/etc/gitconfig git config --system

~/.gitconfig git config —global

.git/config git config


Branches
Creating the branch and switching on it

--o--o--o
[ master ]

$ git checkout -b new-branch

8
Branches
Creating the branch and switching on it

--o--o--o
[ master, new-branch ]

$ git checkout -b new-branch

9
Branches
Creating the branch and switching on it

--o-------o-------o
[ master ]

$ git checkout -b new-branch master~1

10
Branches
Creating the branch and switching on it

[new-branch]
--o-------o-------o
[ master ]

$ git checkout -b new-branch master~1

11
Merge
Join two or more development histories together

[ feature ]
o--o--o
/
--о--о--o--o--o
[ master ]

12
Merge
Join two or more development histories together

[ feature ]
o--o--o
/
--о--о--o--o--o
[ master ]

$ git checkout master


$ git merge feature

13
Merge
Join two or more development histories together

[ feature ]
o--o--o-----------------
/ \
--о--о--o--o--o----------------o
[ master ]

$ git checkout master


$ git merge feature

14
Merge
Join two or more development histories together

[ feature ]
o--o--o-----------------
/ \
--о--о--o--o--o----------------o
[ master ]

$ git checkout master


$ git merge feature

15
Merge
Fast-forward

[ feature ]
o--o--o
/
--о--о--o--o--o
[ master ]
Fast forward merge can be performed when there
is a direct linear path from the source branch to the
target branch.

16
Merge
Fast-forward

--о--о--o--o--o--о--о--о
[ master, feature ]

In fast-forward merge, git simply moves the source


branch pointer to the target branch pointer without
creating an extra merge commit.

17
Rebase
Reapply commits on top of another base tip

--о--о--o--o--o [ master ]
\
о--о [ server ]

18
Rebase
Reapply commits on top of another base tip

--о--о--o--o--o [ master ]
\
о--о [ server ]

$ git checkout server


$ git rebase master

19
Rebase
Reapply commits on top of another base tip

--о--о--o--o--o [ master ]
\
о--о [ server ]

$ git checkout server


$ git rebase master

20
Remote
Repository
$ git clone https://git.itransition.com/project/site.git
Cloning into site
...

$ git remote -v
origin https://git.itransition.com/project/site.git

Clone a repository into a new


directory

21
Remote
Repository
Fetch from and integrate with a local branch
$ git pull

1. $ git fetch

[ origin/master ]
o--o--o
--о--о--o--o--o--о-----o
[ master ]

22
Remote
Repository
Fetch from and integrate with a local branch
$ git pull

2. $ git merge

[ origin/master ]
o--o--o
/ \
--о--о--o--o--o--о-----o
[ master ]

23
Remote
Repository
Publish your changes - push

o--o--o
/ \
--о--о--o--o--o--о-----o
[ master, origin/master ]
$ git push origin master

24
Revert commit changes

Git Revert:

---о---о---о---о
[ master ]

$ git revert master~1

25
Revert commit changes

Git Revert:

---о---о---о---о---о
[ master ]

$ git revert master~1

26
Revert commit changes
What if you need to reset your working copy to
some exact state?

27
Revert commit changes
What if you need to reset your working copy to
some exact state?

First of all stop any process which is in progress

$ git merge --abort


$ git rebase --abort
$ git revert --abort

28
Revert commit changes
What if you need to reset your working copy to
some exact state?

And then update your local version to some


commit state

$ git reset --hard COMMIT_SHA

29
Revert commit changes
$ git reset --hard 12345

$ git commit, git push

о--о [ master ]
/
--о--о--о--о
[ origin/master ]

30
.GITIGNORE
## Directory-based project format:

.idea/

### Node ###

# Logs

logs

*.log

# Runtime data

pids

*.pid

*.seed

# Dependency directory

# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git

node_modules
Gitflow
There is a “development” branch for the test purposes

--о--о--о--о--о [ development ]

32
Gitflow
There are “feature” branches for the feature development

--о--о--о--о--о [ development ]
\
о--о--о [ feature ]

33
Gitflow
There are “release-candidate” branches

о--о--о [ release-2.1 ]
/
--о--о--о--о--о [ development ]
\
о--о--о [ feature ]

34
Gitflow
There is a “master” branch for releases

.--о--о--о [ master ]
|
|
| о--о--о [ release-2.1 ]
| /
--о--о--о--о--о [ development ]
\
о--о--о [ feature ]

35
Gitflow
There are “hotfix” branches

.--о--о--о [ master ]
| \
| о--о [ hotfix ]
| о--о--о [ release-2.1 ]
| /
--о--о--о--о--о [ development ]
\
о--о--о [ feature ]

36
Gitflow

.--о--о--о [ master ]
| \
| о--о [ hotfix ]
| о--о--о [ release-2.1 ]
| /
--о--о--о--о--о--о [ development ]
\ /
о--о--о-------

37
Gitflow

.--о--о--о--о [ master ]
| \ /
| о--о---
| о--о--о [ release-2.1 ]
| /
--о--о--о--о--о--о [ development ]
\ /
о--о--о-------

38
Gitflow

<2.1>
.--о--о--о--о---о [ master ]
| \ / /
| о--о--- /
| о--о--о-----
| / \
--о--о--о--о--о--о--о [ development ]
\ /
о--о--о-------

39
Pros
• Distributed
• Fast
• Light weight branches

40
Cons
• Complexity

41
What to use
• Console
• Built-in IDE or notepad tools
• GitKraken
• SourceTree
Where to host
• GitHub
• GitLab
• Bitbucket
What to read
Scott Chacon and Ben Straub ‘Pro Git’

https://git-scm.com/book/pl/v2
Questions?

You might also like