Git for Beginners Handout
Git for Beginners Handout
This tutorial is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 France License
1 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Objectives
2 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Summary
1. About Version Control Tools
2. Overview of GIT
3. Working locally
8. Extras
3 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 1.
About Version Control Tools
• Definition
• Use cases
• Base concepts
• History
4 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
From: http://en.wikipedia.org/wiki/Revision_control
5 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
1
let’s say your not happy with your latest changes
2
this is useful for understanding and fixing bugs
6 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
7 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• a main branch
• a maintainance branch (to provide bugfixes in older releases)
• a development branch (to make disruptive changes)
• a release branch (to freeze code before a new release)
8 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
3
decentralised tools only
9 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
4
source: the Linux Foundation
10 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Some illustrations
11 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Taxinomy
Architecture:
Concurrency model:
History layout:
13 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• commit often
16 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
17 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
18 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 2.
Overview of GIT
• History
• Git’s design & features
• User interfaces
19 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
History
5
now open source! (since 2016)
20 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• ease of use
21 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• Integrity
• cryptographic tracking of history (SHA-1 hashes)
• tag signatures (GPG)
• Merging
• pluggable merge strategies
• staging area (index)
• Performance
• no delta encoding
22 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Git Commands
23 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
24 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
25 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
26 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 3.
Working locally
• creating a repository
• adding & committing files
• the staging area (or index)
27 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
29 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• the repository
(the whole history of your project)
30 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
31 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Update a file
$ echo 'blah blah blah' >> hello
$ git commit
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: hello
#
no changes added to commit (use "git add" and/or "git commit -a")
32 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
This command commits files (or dirs) directly from the working
tree
7
also named “partial commit”
33 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
34 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Deleting files
git rm file
→ remove the file from the index and from the working copy
git commit
→ commit the index
$ git rm hello
rm 'hello'
$ git commit -m "removed hello"
[master 848d8be] removed hello
1 files changed, 0 insertions(+), 3 deletions(-)
delete mode 100644 hello
35 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Showing differences
git diff [ rev a [ rev b ] ] [ -- path . . . ]
36 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
37 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Diff example
$ echo foo >> hello
$ git add hello
$ echo bar >> hello
$ git diff
--- a/hello
+++ b/hello
@@ -1,2 +1,3 @@
Hello World!
foo
+bar
Resetting changes
git reset cancels the changes in the index (and possibly in the
working copy)
• git reset drops the changes staged into the index8 , but the
working copy is left intact
• git reset --hard drops all the changes in the index and in
the working copy
8
it restores the files as they were in the last commit
39 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
9
since v2.23 you may also use the experimental command git restore
40 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
10
note that git mv is strictly equivalent to: “cp src dst && git rm src &&
git add dst” (file renaming is not handled formally, but heuristically)
41 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Exercises
1. create a new repository
3. launch gitk to display it. Keep the window open and hit F5 after each
command (to visualise the results of your commands)
5. rename the file (either with git mv or git add+git rm), do a git status
before committing (to ensure the renaming is correctly handled)
7. create two new files and commit them. Then modify their content in the
working copy and display the changes with git diff
8. add one file into the index but keep the other one. Display the changes
between:
• the index and the working copy
• the last commit and the index
• the last commit and the working copy
10. run git reset --hard to reset the index and the working copy
42 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 4.
Branching & merging
• How GIT handles its history
• Creating new branches
• Merging & resolving conflicts
43 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
44 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
45 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
46 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Note: it may fail when the working copy is not clean. Add -m to
request merging your local changes into the destination branch.
$ git checkout master
error: Your local changes to the following files would be overwritten by checkout: hello
Please, commit your changes or stash them before you can switch branches.
Aborting
$ git checkout -m master
M hello
Switched to branch 'master'
11
since v2.23 you may also use the experimental command git switch
47 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Merging a branch
This will merge the changes in other branch into the current
branch.
$ git status
# On branch master
nothing to commit (working directory clean)
$ git merge develop
Merge made by recursive.
dev | 1 +
hello | 4 +++-
2 files changed, 4 insertions(+), 1 deletions(-)
create mode 100644 dev
48 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• git merge applies only the changes since the last common
ancestor in the other branch.
→ if the branch was already merged previously, then only the
changes since the last merge will be merged.
49 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Branching example
50 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Merge conflicts
In case of a conflict:
12
Git will refuse to commit the new revision until all the conflicts are
explicitely resolved by the user
52 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Resolving conflicts
Then, once all conflicting files are checked in the index, you just
need to run git commit to commit the merge.
53 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Conflict example
54 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Deleting branches
git branch -d branch name
Exercises
0. use “gitk --all” to display all branches
(and remember to hit F5 after each command to visualise the changes)
56 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 5.
Interacting with a remote
repository
• Overview
• Creating a shared repository
• Configuring a remote repository
• Sending changes (push)
• Receiving changes (pull)
57 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
58 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Team Workflow
59 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
14
default name used by git clone
60 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Examples:
$ git remote add origin /tmp/helloworld.git
61 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
git push
• In case of conflict git push will fail and require to run git
pull first
62 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
15
so that git pull an git push work with that repository by default
63 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
git fetch
64 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
65 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Remote example
66 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
If the branch name does not exist locally, then GIT looks for it in
the remote repositories. If it finds it, then it creates the local
branch and configures it to track the remote branch.
$ git branch --all
* master
remotes/origin/master
remotes/origin/new-fancy-feature
$ git checkout new-fancy-feature
Branch new-fancy-feature set up to track remote branch new-fancy-feature from origin.
Switched to a new branch 'new-fancy-feature'
$ git branch --all
master
* new-fancy-feature
remotes/origin/master
remotes/origin/new-fancy-feature
67 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Cloning a repository
git clone url [ directory ]
• In practice you will rarely use git init, git remote and
git fetch directly, but rather use higher-level commands:
git clone and git pull.
68 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Typical Workflow
69 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Exercises
3. make some commits and synchronise (pull/push) with the origin repository
6. create a new branch, make a commit and publish it to the shared repository
70 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 6.
Hosting your code
• GIT forges
• The bug tracker
• Continuous Integration / Continuous Deployment
71 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• The most popular way to use forge, which hosts the repository
as a project, along with lot of features useful for software
development
72 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
73 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• each issue has a unique id, prefixed with # (eg: #1, #2)
• it contains a text description of the problem and a discussion
• issues may be grouped by tags and/or by milestone
• issues may be assigned to a developer or team
• complex issues may be subdivided into smaller issues
• repository integration: issues are automatically closed when the text
“Fix #id” or “Close #id” is present in:
• the message of a commit merged into the main branch
• the description of a pull request merged into the main branch
74 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
76 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
security consideration
77 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 7.
Working with third-party
contributors
• Common workflows
• Generating & applying patches
• Merging from third-party repositories
78 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Common workflows
16
developers who are not allowed to push to the official repository
80 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Explicit pull/push
git push url local ref:remote ref ... (push as a different name)
81 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Decentralised workflow
82 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
→ fetch the branch branch from the repository url and store it
temporarily17 as FETCH HEAD
$ git fetch git://git.raoul-duke.org/helloworld.git master
From git://git.raoul-duke.org/helloworld.git
* branch master -> FETCH_HEAD
$ gitk FETCH_HEAD
...review the commits ...
$ git merge FETCH_HEAD
17
the FETCH HEAD ref remains valid until the next time git fetch is run
83 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
84 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Generating patches
• git diff
The basic (legacy) way: use git diff
• git format-patch
The modern way: git format-patch converts you history
(commits) into a series of patches (on file per commit) and it
records the metadata (author name, commit message) 18
18
Note: git format-patch does not preserve merge history & conflicts
resolution. You should only use it when your history is linear.
85 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Generating patches
Example:
$ git format-patch origin/master
0001-added-foo.patch
0002-removed-bar.patch
86 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Applying patches
git am file1 [ file2 ...]
19
am originally stands for “apply mailbox”
20
actually GIT distinguishes between the author and the committer of a
revision (usually they refer to the same person, but not when running git am)
87 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Exercises
1. look up the helloforge project on the istic forge at:
https://gitlab.istic.univ-rennes1.fr/abaire/helloforge
2. clone the repository (click on the Clone button to get the repository url, prefer
using the ssh url rather than https)
3. create one or more commit, then try to push your master branch (note: this
should fail because the master branch is protected)
4. push your branch under a different name, eg:
$ git push origin master:my_new_branch_name
5. create a merge request for your branch (to merge it into origin/master). You
can do that either in the merge requests page on the forge or by following the
url displayed by the git push command.
6. once your merge request is created, browse its details (discussion, changes, . . . ),
then approve it to have it merged into the master branch.
7. run git pull and check the results in gitk
8. repeat steps 3 to 7, but by publishing your branche in a forked repository (click
on Fork on the project page to create your fork)
88 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Part 8.
Extras
• Some advices
• Common traps
• Documentation
• Next tutorial
89 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
90 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
91 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• git reset reverts the index, but keeps the working copy
unchanged
→ do git reset --hard if you need to revert the working
copy too
92 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
• GIT is not forgiving, do not ignore its warnings and do not use
--force unless you have a clear idea of what you are doing
93 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
94 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
94 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
94 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
94 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
94 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
95 / 96
Version Control GIT Intro Local GIT Branches Remote GIT Forges Bazar Extras
Further documentation
• man git cmd (tough & exhaustive)
• man gitglossary
• The Git book
http://git-scm.com/book
https://www.atlassian.com/git/workflows
96 / 96