KEMBAR78
Git Basics: Learn Do Real Work | PDF | All Rights Reserved | Software Engineering
0% found this document useful (0 votes)
41 views56 pages

Git Basics: Learn Do Real Work

Git Bacis commands

Uploaded by

neeraj12121
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)
41 views56 pages

Git Basics: Learn Do Real Work

Git Bacis commands

Uploaded by

neeraj12121
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/ 56

Git Basics

Copyright 2018. All rights reserved


learn = do real work
Learning Objectives

Version Control Systems Installing Git and GitHub Git Basics

Copyright 2018. All rights reserved


learn = do real work
Version Control Systems

Copyright 2018. All rights reserved


learn = do real work
What is Version Control?

● A system that keeps records of your changes


● Allows for collaborative development
● Allows you to know who made what changes and when
● Allows you to revert any changes and go back to a previous state

Copyright 2018. All rights reserved


learn = do real work
Git Basics

Copyright 2018. All rights reserved


learn = do real work
Keep track of changes to code.

i n t a = 1;
i n t b = 2;
i n t c = 3;

Create f i l e

Copyright 2018. All rights reserved


learn = do real work
Keep track of changes to code.

i n t a = 1; int a = 1;
i n t b = 2; int b = 2;
i n t c = 3; int c = 3;
int d = 4;

Create f i l e Add a l i n e

Copyright 2018. All rights reserved


learn = do real work
Keep track of changes to code.

i n t a = 1; int a = 1; i n t a = 1;
i n t b = 2; int b = 2; i n t c = 3;
i n t c = 3; int c = 3; i n t d = 4;
int d = 4;

Create f i l e Add a l i n e Remove a l i n e

Copyright 2018. All rights reserved


learn = do real work
Synchronizes code between different people.

i n t b = 2;
i n t c = 3;

Copyright 2018. All rights reserved


learn = do real work
Synchronizes code between different people.

i n t b = 2;
i n t c = 3;

i n t b = 2; i n t b = 2;
i n t c = 3; i n t c = 3;

Copyright 2018. All rights reserved


learn = do real work
Synchronizes code between different people.

i n t b = 2;
i n t c = 3;

i n t a = 1; i n t b = 2;
int b = 2; i n t c = 3;
i n t c = 3; i n t d = 4;

Copyright 2018. All rights reserved


learn = do real work
Synchronizes code between different people.

int bv= 21;


int c = 32;
int c = 34
int d = 4;

i n t a = 1; i n t b = 2;
i n t b = 2; i n t c = 3;
i n t c = 3; i n t d = 4;

Copyright 2018. All rights reserved


learn = do real work
Synchronizes code between different people.

int a = 21;
int b = 23;
int c= 34;
int d = 4;

int a = 1; int b = 12;


int b = 2; int c = 32;
int c = 3; int d= 43;
int d = 4; int e = 4;

Copyright 2018. All rights reserved


learn = do real work
Test changes to code without losing the original.

int a = 1;
int b = 2;
int c = 3;
int d = 4;

Copyright 2018. All rights reserved


learn = do real work
Test changes to code without losing the original.

i n t a = 1;
i n t b = 2;
i n t c = 3;

int a = 1;
int b = 2;
int c = 3;
int d = 4;

Copyright 2018. All rights reserved


learn = do real work
Test changes to code without losing the original.

i n t a = 1;
i n t b = 2; int a = 1;
i n t c = 3; int b = 2;
int c = 3;
int d = 4;

int a = 1;
int b = 2;
int c = 3;
int d = 4;

Copyright 2018. All rights reserved


learn = do real work
Revert back to old versions of code.

i n t a = 1; int a = 1; i n t a = 1;
i n t b = 2; int b = 2; i n t c = 3;
i n t c = 3; int c = 3; i n t d = 4;
int d = 4;

Create f i l e Add a l i n e Remove a l i n e

Copyright 2018. All rights reserved


learn = do real work
Revert back to old versions of code.

i n t a = 1; int a = 1;
i n t b = 2; int b = 2;
i n t c = 3; int c = 3;
int d = 4;

Create f i l e Add a l i n e

Copyright 2018. All rights reserved


learn = do real work
What is Git?

Keeps track of changes to code.

Synchronizes code between differentpeople.

Test changes to code without losing the original.

Revert back to old versions of code.

Copyright 2018. All rights reserved


learn = do real work
git clone <url>

int a = 21;
Int b = 32;
makes a copy of a repository stores it on int
int
c = 43;
d = 4;

your computer
a "fork" creates your own copy of someone
else's repository

Copyright 2018. All rights reserved


learn = do real work
git clone <url>

in n tt aa==121 21;
;
Ii nntt bb==32;32;
makes a copy of a repository in
in
n tt cc= =
343;43;
n tt dd ==4 ;4 ;

stores it on your computer


a "fork" creates your own copy
of someone else's repository

g i t clone <url>

Copyright 2018. All rights reserved


learn = do real work
git clone <url>

in n tt ba==21;21;
Ii nntt cb==23232;
;
makes a copy of a repository in
in
n tt c34;
c = 43;
n tt dd ==4 ;4 ;

stores it on your computer


a "fork" creates your own copy
of someone else's repository

int a = 1;
int b = 2;
int c = 3;
g i t clone <url> int d = 4;

Copyright 2018. All rights reserved


learn = do real work
git add <filename>

in n tt aa==21;21;
II nnttb b== 32;32;
adds a file to "staging area" tells git to include the in
in
n tt c=
c 34
=3; 43;
n tt dd ==4 ;4 ;

file in the next revision to the repository


Git add * adds all changed files

int a = 1;
int b = 2;
int c = 3;
int d = 4;

Copyright 2018. All rights reserved


learn = do real work
git add <filename>

in n tt ba =
= 21;21;
Ii nntt cbb =
= 32;
32;
adds a file to "staging area" tells git to include the in
in
n tt dc= 34;
= 43;
n tt dd ==4 ;4 ;

file in the next revision to the repository


Git add * adds all changed files

int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;

Copyright 2018. All rights reserved


learn = do real work
git add <filename>

in n tt aba== 12;21;
Ii nntt cbb =
= 23;32;
adds a file to "staging area" tells git to include the in
in
n tt cdc= 3
=43;43;
n tt dd ==4 ;4 ;

file in the next revision to the repository


Git add * adds all changed files

int a = 1;
int b = 2;
int c = 3;
g i t add f o o . c int d = 4;
int e = 5;

Copyright 2018. All rights reserved


learn = do real work
git add <filename>

in n tt aba =
= 1221;
1;
Ii nntt bcbb== 2332;
2;
adds a file to "staging area" tells git to include the in
in
n tt cdc ==3443;
3;
n tt dd ==4 ;4 ;

file in the next revision to the repository


Git add * adds all changed files

int a = 1;
int b = 2;
int c = 3;
g i t add f o o . c int d = 4;
int e = 5; Changes t o be committed:

m o d if ie d: f o o . c

Copyright 2018. All rights reserved


learn = do real work
git commit -m "message"

saves the changes to repository as a new revision (a


in n tt aba== 12;
21;
"commit") records a message Ii nntt bcbb== 2332;
in
2;
n tt cdc ==3443;
3;
Git commit –am "message" inn tt dd ==4 ;4 ;

Adds and commits in same step

int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;

Copyright 2018. All rights reserved


learn = do real work
git commit -m "message"

saves the changes to repository as a new revision (a


in n tt aba =
= 1221;
1;
"commit") records a message Ii nntt bcb =
in
= 23;
32;
n tt cdc ==43;43;
Git commit –am "message" inn tt dd ==4 ;4 ;

Adds and commits in same step

int a = 1;
int b = 2;
int c = 3;
g i t commit -m int d = 4;
int e = 5;
"Add l i n e "

Copyright 2018. All rights reserved


learn = do real work
git commit -m "message"

saves the changes to repository as a new revision (a


in n tt aba =
= 1221;
1;
"commit") records a message Ii nntt bcbb== 2332;
in
2;
n tt cdc ==34;43;
Git commit –am "message" inn tt dd ==4 ;4 ;

Adds and commits in same step

int a = 1; int a = 1;
int b = 2; int b = 2;
int c = 3; int c = 3;
g i t commit -m int d = 4; int d = 4;
int e = 5;
"Add l i n e "
Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git status

in n tt ba == 1221;
1;
Ii nntt bcb == 2332;
2;
-shows current status of repository in
in
n tt cdc ==34;43;
n tt dd ==4 ;4 ;

int a = 1; int a = 1;
int b = 2; int b = 2;
int c = 3; int c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git status

in n tt aba =
= 21;
21;
Ii nntt bcbb== 2332;
2;
- shows current status of repository in
in
n tt cdc ==43;43;
n tt dd ==4 ;4 ;

int a = 1; int a = 1;
int b = 2; int b = 2;
int c = 3; int c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e
g i t st a t u s

Copyright 2018. All rights reserved


learn = do real work
git status

in n tt aba =
= 21;21;
Ii nntt bcb =
= 23;32;
- shows current status of repository in
in
n tt dc= 3=43;43;
n tt dd ==4 ;4 ;

int a = 1; int a = 1;
int b = 2; int b = 2;
int c = 3; int c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e
g i t st a t u s
On branch master
Your branch i s ahead o f ' o r i g i n / m a s t e r ' by 1 commit.
(use " g i t push" t o p u b lis h your l o c a l commits)

Copyright 2018. All rights reserved


learn = do real work
git push

in n tt aba== 1221;
1;
- sends committed changes to Ii nntt bcbb== 2332;
in
2;
n tt cdc ==43;43;

remote repository inn tt dd ==4 ;4 ;

more explicitly, could write


Git push origin master

int a = 1; int a = 1;
int b = 2; int b = 2;
int c = 3; int c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git push

i n tt aba == 1221;
1;
- sends committed changes to Ii nntt bcbb== 2332;
2;
in n tt cdc ==3443;
3;
remote repository i n tt dd ==4 ;4 ;

more explicitly, could write


Git push origin master

int a = 1; int a = 1;
g i t push int
int
b = 2;
c = 3;
int
int
b = 2;
c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git push

in n tt aba == 1221;
1; int a = 1;
Ii nntt bcbb== 2332;
2; int b = 2;
- sends committed changes to in
in
n tt cdcc == 34;
n tt dd= =
43;
4; 4;
int
int
c = 3;
d = 4;

remote repository int e = 5;

more explicitly, could write Add l i n e

Git push origin master

int a = 1; int a = 1;
g i t push int
int
b = 2;
c = 3;
int
int
b = 2;
c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git pull

int a = 1; int a = 1; int a = 1;


int b = 2; int b = 2; int c = 3;
- retrieves changes from int
int
c = 3;
d = 4;
int
int
c = 3;
d = 4;
int
int
d = 4;
e = 5;

remote repository int e = 5;

Add l i n e Remove l i n e

int a = 1; int a = 1;
int b = 2; int b = 2;
int c = 3; int c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git pull

int a = 1; int a = 1; int a = 1;


int b = 2; int b = 2; int c = 3;
- retrieves changes from int
int
c = 3;
d = 4;
int
int
c = 3;
d = 4;
int
int
d = 4;
e = 5;

remote repository int e = 5;

Add l i n e Remove l i n e

int a = 1; int a = 1;
git pull int
int
b = 2;
c = 3;
int
int
b = 2;
c = 3;
int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
git pull

int a = 1; int a = 1; int a = 1;


int b = 2; int b = 2; int c = 3;
- retrieves changes from int
int
c = 3;
d = 4;
int
int
c = 3;
d = 4;
int
int
d = 4;
e = 5;

remote repository int e = 5;

Add l i n e Remove l i n e

int a = 1; int a = 1; int a = 1;


git pull int
int
b = 2;
c = 3;
int
int
b = 2;
c = 3;
int
int
c = 3;
d = 4;
int d = 4; int d = 4; int e = 5;
int e = 5;

Add l i n e Remove l i n e

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

git pull

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

git pull
CONFLICT (content): Merge conflict in reverse.py
Automatic merge failed; fix conflicts and then
commit the result.

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

i n t a = 1;
<<<<<<< HEAD
i n t b = 2;
=======
i n t b = 0;
>>>>>>> 5468697320697320435335302e
git pull
i n t c = 3;
i n t d = 4;
i n t e = 5;

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

i n t a = 1;
your <<<<<<< HEAD conflicting commit
changes { i n t b = 2;
=======
remote
changes { i n t b = 0;
>>>>>>> 5468697320697320435335302e
git pull
i n t c = 3;
i n t d = 4;
i n t e = 5;

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

i n t a = 1;
<<<<<<< HEAD
i n t b = 2;
=======
i n t b = 0;
>>>>>>> 5468697320697320435335302e
git pull
i n t c = 3;
i n t d = 4;
i n t e = 5;

Copyright 2018. All rights reserved


learn = do real work
Merge Conflicts

- when two different commits


can't be automatically merged
need to be resolved

int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
git pull

Copyright 2018. All rights reserved


learn = do real work
Git log

- shows a history of commits and messages

g i t lo g

Copyright 2018. All rights reserved


learn = do real work
Git reset
$ git log
commit dfb8c46953598dfd57124b11027b29f21b818dad (HEA
origin/master, origin/HEAD)
Author: Varun Panicker <varunppanicker@gmail.com>
Date: Fri Apr 6 20:03:32 2018 +0530
- Git reset –hard <commit>
reverts code back to a previous commit changed to 77777
- Git reset –hard origin/master
commit f22f947ff36701c845e67e9079ff8d12abdfeda7
reverts code back to remote repository version Author: Varun Panicker <varunppanicker@gmail.com>
Date: Fri Apr 6 19:58:22 2018 +0530

Changed a to 77

int a = 1; int a = 1; int a = 1;


int b = 2; int b = 2; int c = 3;
int c = 3; int c = 3; int d = 4;
int d = 4; int d = 4; int e = 5;
int e = 5;

Add Line Remove Line

Copyright 2018. All rights reserved


learn = do real work
Git reset

- Git reset --hard <commit>


reverts code back to a previous commit
- Git reset --hard origin/master
reverts code back to remote repository version

int a = 1; int a = 1; int a = 1;


g i t re se t --h a rd int
int
b = 2;
c = 3;
int
int
b = 2;
c = 3;
int
int
c = 3;
d = 4;
4761626 int d = 4; int d = 4; int e = 5;
int e = 5;

Add Line Remove Line

Copyright 2018. All rights reserved


learn = do real work
Git reset

- Git reset--hard <commit>


reverts code back to a previous commit

- Git reset--hard origin/master


reverts code back to remote repository version

int a = 1; int a = 1;
g i t re se t --h a rd int
int
b = 2;
c = 3;
int
int
b = 2;
c = 3;
4761626 int d = 4; int d = 4;
int e = 5;

Add l i n e

Copyright 2018. All rights reserved


learn = do real work
Branching

Branch is a version of the repository.

Each branch has its own commit history and current version.

Copyright 2018. All rights reserved


learn = do real work
git branch

shows all branches of code


create a branch with git branch <branch_name>
switch to ("checkout") a new branch with git checkout <branch_name>

int a = 1;
int b = 2;
master int c = 3;
int d = 4;

Copyright 2018. All rights reserved


learn = do real work
git branch

shows all branches of code


create a branch with git branch <branch_name>
switch to ("checkout") a new branch with git checkout <branch_name>

int a = 1;
int b = 2;
master int c = 3;
int d = 4;

g i t branch t e s t s

Copyright 2018. All rights reserved


learn = do real work
git branch

shows all branches of code


create a branch with git branch <branch_name>
switch to ("checkout") a new branch with git checkout <branch_name>

int a = 1;
int b = 2;
master int c = 3;
int d = 4;

g i t branch t e s t s

int a = 1;
int b = 2;
tests int c = 3;
int d = 4;

Copyright 2018. All rights reserved


learn = do real work
git merge

- Git merge <branch_name>


Merges the branch branch_name with current branch

int a = 1;
int b = 2;
master int c = 3;
int d = 4;

int a = 1; int a = 1; let a = 0;;


int b = 2; int b = 2; int b = 2;
tests int c = 3; int c = 3; int c = 3;
int d = 4; int d = 4; int d = 4;
int e = 5; int e = 5;

Copyright 2018. All rights reserved


learn = do real work
git merge

- Git merge <branch_name>


Merges the branch branch_name with current branch

int a = 1; int a = 1; let a = 0;;


int b = 2; int b = 2; int b = 2;
master int c = 3; int
int
c = 3;
d = 4;
int
int
c = 3;
d = 4;
int d = 4;
int e = 5; int e = 5;
g i t merge t e s t s

int a = 1; int a = 1; let a = 0;;


int b = 2; int b = 2; int b = 2;
tests int c = 3; int c = 3; int c = 3;
int d = 4; int d = 4; int d = 4;
int e = 5; int e = 5;

Copyright 2018. All rights reserved


learn = do real work
Copyright © 2017 by GreyAtom Edutech Pvt. Ltd.

All Rights Reserved. No part of this publication may be reproduced, stored in a


retrieval system, or transmitted, in any form or by any means, electronic,
mechanical, photocopying, recording, or otherwise, without the prior written
permission of GreyAtom Edutech Pvt. Ltd.

Thank You!
Copyright 2018. All rights reserved
learn = do real work

You might also like