By: Feven Tadesse Title: Trainer at The Coding School: Orange Digital Center
By: Feven Tadesse Title: Trainer at The Coding School: Orange Digital Center
GIT
Orange
Digital
Center
About ODC
POSTMAN
GIT
ZEPLIN
OPEN SOURCE
3 AASTU Training
Objective Of These Session
✔ You will be able to understand the popular version control system, and how to use it
✔ You will be able to work with teams and collaborate on a common project seamlessly without
✔ You will be able to work on open source projects with flexibility and security you need
4 AASTU Training
Outline Of The Session
Intro To Version Control System
👉 What is VCS?
👉 Why VCS?
👉 Distributed VCS?
Intro To Git
👉Getting Started With Git
👉Git Hosting Services
Deeper Into Git
👉 Go Local
👉 Git configuration
👉 Git Basics
👉 Working With Branches
👉 Merging and Conflict Resolution
Mini
5 GITTraining
AASTU Project
Rules For Success!
Practice is the best way to learn. So do all the exercises along the way
6 AASTU Training
Ice Breaker :)
Question ?
7 AASTU Training
VERSION CONTROL SYSTEM
8 AASTU Training
What is VCS?
Version control is a process of tracking and managing changes to code
Terms is VC:
Repository - collection of files of various
versions of a project (Local and Remote)
Collaboration - developers working(contributing)
together project in a synchronized way
9 AASTU Training
Why VCS?
Who / Why / When a change is made (A complete long-term change history of every file)
Increase traceability (can connect to project management and other tools like trello, jira, slack)
10 AASTU Training
Distributed VCS
Each collaborator has a local copy of the repository
11 AASTU Training
GIT INTRODUCTION
12 AASTU Training
What is Git?
The most popular distributed version control system
13 AASTU Training
Little History
Created by Linus Torvalds in 2005
14 AASTU Training
Getting Started With Git
Git is already installed on Mac OS and Linux
15 AASTU Training
Git Hosting Service
What is the difference between git and gitHub or gitLab??
16 AASTU Training
Exploring Gitlab…
Let’s create a new directory on our machine and open the terminal in that directory and type:
git clone https://gitlab.com/Fevtad/git-workshop.git
17 AASTU Training
Go Local
Now we have a local copy(local repo) of our remote repository
18 AASTU Training
Git Basics
We can head to ‘git-workshop’ folder and create an html file ‘my_html’and type
<html>
<body>
<h1>This is the first clone</h1>
</body>
</html>
Question : If I add another line of code like : <h1>This is another line</h1>. Save and close the file how
can I go back to the previous version?
Can git actually help with tracking every version of all of my files in a folder??
19 AASTU Training
Cont …
Every single version of every file in a repository can be tracked using git.
20 AASTU Training
Cont...
Now let’s check the status of our git again. How do we that?
So now we shall tell our local repo about our change right?
You should tell git who you are, meaning you should
configure your git
21 AASTU Training
GIT CONFIGURATION
22 AASTU Training
Git Configuration
23 AASTU Training
Git Basics
So now our local repo has all our changes. So we can ‘push’
our local changes to the remote repo
25 AASTU Training
What did we learn so far
Can we now reload our gitlab page and see if there are changes?
26 AASTU Training
GIT BRANCHING
27 AASTU Training
Branch It Out
A separate and independent line of development in a repository
29 AASTU Training
Deeper Into Branches
Let’s make some changes to our branch :
<html>
<body>
<h1>This is the first clone</h1>
<h1>This is my dev-fev branch</h1>
</body>
</html>
30 AASTU Training
Cont…
So we need to add this change and then commit:
git add .
git commit -m “created new branch”
Do we have an issue??
31 AASTU Training
Cont...
Since we don’t have our ‘dev-fev’ branch remotely we need
to create the branch and push to that branch using:
git push --set-upstream origin dev-fev
Shall we checkout to our master branch and see how our html file is affected?
33 AASTU Training
Best Practices While Working
With Branches
Master/Main branch is the default branch created when you
first create your repo
When working on your repo don’t directly use the master branch.
Create another branch and push your changes there.
You can finally merge your changes with the master.
34 AASTU Training
Let’s Bring It Together
We have been working on our new branch for a while now
Taking changes from one branch and applying it to another is called merging
35 AASTU Training
Cont...
To merge I need to first be in my destination branch
For our case it is our master branch. So make sure you have checked out
to your master branch. Then:
git merge SOURCE-BRANCH-NAME
<html>
<body>
<h1>This is the first clone</h1>
<h1>This is my dev-fev branch</h1>
</body>
</html>
36 AASTU Training
Cont...
If we check our git status we can see that our local branch is ahead
of our remote by 1 commit. Why?
You can see that the last commit message to our master branch is same as our new branch
37 AASTU Training
GIT CONFLICTS
38 AASTU Training
Resolve Some Conflicts
What is conflict?
When Git doesn’t know how to merge two branches
Why conflict?
Different changes on same file and same line
Changing a file on one branch and that file is deleted in another
How to resolve?
1) I can abort the merge
git merge --abort
2) Or I can fix it manually. We’re about find that out
39 AASTU Training
Cont...
Since our last activity was merging the two branches, their
my_html.html is the same
40 AASTU Training
Cont...
And for our master branch:
<html>
<body>
<h1>This is the first clone</h1>
<h1>This is master conflict</h1>
</body>
</html>
Let’s also add and commit our change
Now let’s do what we did earlier. Let’s merge the new branch
to our master branch. How do we do that?
41 AASTU Training
Cont...
Did you see something like this:
<html>
<body>
<h1>This is the first clone</h1>
<<<<<<< HEAD(Current Change)
<h1>This is master conflict</h1>
=======
<h1>This is dev-fev conflict</h1>
>>>>>>> dev-fev(Incoming Change)
</body>
</html>
You can also see the different options just under the first <h1>
to accept current change, to accept incoming change,...
42 AASTU Training
Cont...
Yeah! We have successfully created a conflict!
44 AASTU Training
Wanna Guess What Pull Does
Obviously you are not the only one working on this project
So let’s say Feven pushed a change to the master branch. How would
you have that change locally?
You PULL!
46 AASTU Training
What We’re Doing
● Team of two
● Work on a project - Ecommerce site
● The site includes three pages
○ Landing page (both team members)
○ product list page (one team member)
○ customer list page (one team member)
47 AASTU Training
TAKEAWAYS??
48 AASTU Training
TakeAway
You can realize how powerful git is in resolving all your misery!
50 AASTU Training
Orange Digital Center
Ethiopia
Orange
Digital
Center