0% found this document useful (0 votes)
75 views

Git Notes

1) Git is a version control system used to track changes to files and coordinate work on projects. It allows users to commit snapshots of changes to a project repository. 2) The document discusses basic Git commands like git init, git add, git commit, git status and git log to manage a local repository and commit changes. 3) Branches in Git allow users to develop features independently in parallel timelines called branches, which can later be merged back together into a main branch like master.
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)
75 views

Git Notes

1) Git is a version control system used to track changes to files and coordinate work on projects. It allows users to commit snapshots of changes to a project repository. 2) The document discusses basic Git commands like git init, git add, git commit, git status and git log to manage a local repository and commit changes. 3) Branches in Git allow users to develop features independently in parallel timelines called branches, which can later be merged back together into a main branch like master.
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/ 20

E

Git

-Hitesh Choudhary

hiteshdotcom -> X or twitter

find me on youtube - Hitesh Choudhary


gig
- A
talk on

githa
it & different t
L
software

Version Control
->
System
-> track files for changes
->
Learning->
Path
Get the basics
-> Use it daily
-> face the Problem -> solve the problem
- I have covered more than basics in this
Repo Git
>

on
system
US
tracking (Repo)
git--version
Git Rebo
->

1 -
Not tracked

-> Git
history Seo
-> git status

git init (one time per project)


·

git -
a hidden folder to keep history of all files
& sub-folders
Don't re-share without
tagging me !
=> Commit

Working Dis

point (like game)


V
check
git add

> Staying Area

git commit
Write - Add - Commit Repo ↳

git bush
,
Github
=>

Stage
- git init
Create file or files
git add filel filed II git add ·

git status
->
Commit
git commit -m "a
good descriptive message"
status
git
-> Repeat 2-3 times

git log (log of commits with commit hash)


=>
Atomic Commits
-> keep commits centric to one
feature ,
one component or

fix Focused
on

Present
. on one

Past commit message


thing
-> or

·Depends [Present tense , Imperatives


order to codebase
give -P
·
Don't care

editor" code--wait"
git config--global↳> core

changes default editor to Us Code


git log--oneline (too much in does of log
gitignoreDon't
-> .

want to track some files


-> node modules .
/
API
key Secret
,

online
->
get template ,
batterns
M
can be tricky

-> Commit behind the scene

Hash Hash Hash


- Parent
-
Parent - null Parent
In fo Info Info
- Branches
> Like an alternative timeline (not from D8
.
.

Strangel
0
-o
-

0-0-0-0-0 -
0 you are
always on some

Lo-to-o Branch

is main really special ?

->
Head -> master
Head points to where a branch is
currently at

master. "
o

-
-

&
master " Find
branch
git
branch bugfixe
git
git switch bugfix
git log
git switch master

git Switch - dark -

mode (create a branch & move there)


git checkout -
b bink-mode

before to another branch


-> commit
switching
->
go
to .

git folder & checkout HEAD file


branches
Merging the
->

HEAD

a mater
=

- -

git switch master


git merge bugfix
sigfic fast forward
merge

-> Not fast forward merge


-o -ot
2 parents
-0-Q-of"master--HEAD
-

tries best to resolve conflicts


git
->
>HEAD

My-branch
that are on
you

=====

es
3))
->

fix
Conflict that came from another branch (merge)
buy

keep whatever you want ,


remove markers & Save
=>

Git Diff (informative command)


git diff
(compare working staging ( with

-> How to read diff


· a - file 1 R b- file 2
(same file over time)
E
file t indicates change in file
I
- - -
D

·
+ +
file s
lines little preview of it
changes in &
·

->> Git Stash


-> create a repo ,
work & commit on main
-> switch to another branch & work
->
conflicting changes do not allow to switch
branch ,
without commits
git stash ↳you can switch branch) :

git stash pop (bring back those


changes)
optional
git stash
apply (apply changes & keep them in stash)

=> More Commands


git checkout <Hash) (Detach Head) :
new branch
git switch main (re-attach Head
git checkout HEAD-2 (look at & commit
prior)
filename (get version)
git restore back to last commit
-> Rebase -
alternative to
merging
->

-
clean up tool (Clean up commits)
-o -

-
W
⑧ 0-0-0 3
4 I
commits
merge
-
-0-0-0-0-0 -Rebase
master shgfis

git init
work & commit on main branch
foota
git switch-c
work & add a
foote in feature branch
git commit -
am "add footh text"
git switch main

work & add her section on main branch

git switch foots


git merge main

Work & add more


info in footer
do
if there is more work on main ,
more
merge
-get on
foots branch & rebate
rebase main
git
work & add more on main branch
more to foote branch

git rebase main

E
sp
By

Erect
Never Rebase commits that you have shared
Pushed to Github NEVER rebase -
have strict commit
some
companies guidelines regarding
to be added
messages like ticket id . You can use rebase
to re-write
your git history before sending ,
a
bull request
git rebase -i HEADWS (order is reverse)
pick reword
, (your hash also gets a
change)
these are commands
many more

like
->> Tags :
a
sticky note

git tag betax"


git tag-1" *

->

light weight tags & Annotated tags--"


git tag v2 1 .
0 .

git tag -a0 v3 .


.
8

git show v3 .
0 . 0
git tag hitesh 2467b289 (tag previous tag)
tags needs to be unique
git tag-d hitesh (delete tags)
git bush--tags (push to remote repol

Reflog
track of where
git keeps your HEAD is
moving ,

ex :

branch to branch
These logs are local ,
not shared Rare expired
git reflog show HEAD
-> Github Discussion
Git is a software & Github is a service to host git online
·
Github - collaboration Backup + Open Source
+

Gitlab or Bitbucket

git clone [URL)

git config--global username "hitesh choudhary"


"hitesh Chiteh
"

git config--global user .


email . a;

Setup SSH
keys to connect with github github/

uses SSH to allow


you to push code .
Password based code

bush is not allowed

·
check instruction for your 05 on
github website
,
as

that's best P updated resource


git remote v

git remote add name url

git remote add


origin hips :
// github com/hithchoudhary/chai git
.
.

git remote rename old name new name

git remote remove name

git bush <remote) <branch)


git bush origin main

git bash <remote) local Branch : remote Branch

git push-n origin main


-
u
setup an upstream that allow you to run future command

git bush
& it push the code
directly to
github
When clome a repo you get just main branch connected
you , ,

rest of remote branches are not configured .

branch-name
git switch
connects remote ↳ tanch to local

git branch -
I

local Rebo Remote Repo


Work
stage


git fetch

get into but don't put


2
git pull↑
in
my work

get info R add it in work


my
fetch
git pull- git + git merge
git pull origin main
(changes will be merged to main)
Discuss github features on website like
collaborators
Adding
-

-
Read me file
->
matk down format
Gists
Adding
->

-> Code spaces


-> Der Container
All this is discussed in class or video

If you find this being shared , please tay me

"Hitesh Choudhary" on
you tube
whitesh dot com on twitte or X

You might also like