0% found this document useful (0 votes)
80 views5 pages

Untitled

This document provides instructions for learning Git and GitHub commands. It covers installing Git, setting the username and email, adding and committing files, branching, merging, pushing code to remote repositories, and more. The document includes code examples for each topic to demonstrate how to use the various Git commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views5 pages

Untitled

This document provides instructions for learning Git and GitHub commands. It covers installing Git, setting the username and email, adding and committing files, branching, merging, pushing code to remote repositories, and more. The document includes code examples for each topic to demonstrate how to use the various Git commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------
-----------------------

** LEARN GIT HUB


(command for git Base) **
(Created By
Harshal Ghadiya)

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------

//set token error solution URL:


https://stackoverflow.com/questions/68788998/authentication-was-removed-please-use-
a-personal-access-token-instead
// today token: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

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

1. INSTALL GIT LATEST VERSION

// set token(using this command insite a git base) :git remote set-url origin
https://<token>@github.com/username/HarshalGhadiya.git
// User name : HarshalGhadiya
// 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(temp token)

CODE:
// git --version
// git help (-a,--all)
// cheak current path : pwd
// change directory : d/
// create a directory : mkdir
// git branch -M main :this can will be use a set default branch master to a main.
// git branch -r :this can will be show a remote branches
// create a file inside a directory : touch index.html(file name with touch
command)
// Initialized empty Git repository in D:/projects/sampleproject/.git/ : git init
// ls (show all file in curtrent folder)
// rm <file nam> :remove file from given folder
// code . :this can will be use for open a project or fill in the vscode
// git clone (url) :this can will be clone a git project

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------

2. CHEAK & SET USERNAME AND EMAIL (this can will be show the user/project/system
level configpath configaration)
CODE : git config --list --show-origin

// git config --local user.email [email protected] (set a email)


// git config user.email(cheak email)

// git config --local user.name HARSHAL


// git config user.name (cheak name)
// git config --unset user.email (unset a email & name from projects)
// git config --local --remove-section user

// git config --global --unset user.name (globle level)


// git config --global --remove-section user

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------

3.git (add,status,log)
// git add (file_name) : add file working area to stagging area
// git status : cheak file status
// git init : intialiaze a repositry
// git log : showing how much time commite done (intitial + final commit)
// git add . : add all file in staging area

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------------------

4.GIT DIFF COMMAND


// git diff :showing diffrence between working area to stagging area
// git diff --staged : showing diffrence betwwen staging area to repository area
// git diff head : showing diffrence between working area to repository area

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------------------------

5.How to git stores the data. using git cat-file command


// git cat-file (unique key) -p

example: git cat-file b11111e8bc75252c82653077dbd0c9bc027891ed -p

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------

6.git mv and restore command (changing file name & restore file)
example: git mv h.text h.html (changed successfully)

example: git restore --staged a.html (restore stagging area to working area)

///////////GIT RESET //////////


git reset Head~(number of step) :reset a head back side given number of step

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------

7.GIT BRANCHING
// THIS ALL COMMAND SWITCH BETWEEN A BRANCHES AND COMMITES

// git checkout -b loginfeature(branch name):creating a new branch and they can


will be directly connect to the master
// git checkout loginfeature(head pointer movie to the this branch and pointing
that place)
// git checkout master (head move and pointing to the master)
// git branch :(showing all branch)
// git log --oneline :(showing all branch commit in one line)
// git branch -m my_branch(changing name) :changing current branch name
// git branch -d my_branch(delete branch name):currently branch will be deleted
(not any commit inside a branch)
// git branch -D my_branch(delete branch name):currently branch will be deleted (Do
any commit inside a branch)

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------------------

8.GIT CHECKOUT

// THIS ALL COMMAND SWITCH BETWEEN A BRANCHES AND COMMITES

//git checkout master:head will be point to the master (replace master accoding to
your branch name)
//git checkout - : this can will be move a head from a previouse(means goback from
one step)
//git checkout Head~(number) :this can will be going back from give a number of
commit
//git checkout -- (filename) : this command will be use discard those file changes
//git checkout Head (filename):same work as above line ( " )

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------

9.GIT SWITCH AND RESTORE

// git restore (filename) : (restore the all modified work)


//git restore --source Head~(number) (file name) : this can will be restore the
number of step defining file(example:git restore --source Head~2 index.txt)

//git switch (branch name) : (this commmand will be switch only between the two
branches)
//git switch -c (new branch name) :(this command will be genrate a new branch and
switch given branch name)(example : git switch -c loginbranch )
//git switch - :this can will be move from a previous branch

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------
GIT-HUB
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------------
10. Ssh key-pair between com & git hub

step-1:(add your email)

$ ssh-keygen -t rsa -C "[email protected]"


step-2.Check eval status

$ eval "$(ssh-agent -s)"

//Note:add generated key in your git account

step-3 Add your SSH private key to the ssh-agent. If you created your key with a
different name,
or if you are adding an existing key that has a different name, replace id_ed25519
in the
command with the name of your private key file.

$ ssh-add ~/.ssh/id_ed25519
other : ssh-add ~/.ssh/id_rsa
other: cat ~/.ssh/id_rsa.pub ::=>this Comand give a Hashing Formated keys

step-4 cheak confirmation connection

$ ssh -T [email protected]

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------

11. Add, Rename & Remove Remote origin url to the Git Repo

// git remote add origin <url>


// git remote rename <old-name> <new-name>
// git remote remove <name>

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------------------------------

12.git push Requests

// git push origin master : push a code in master branch (you can add your remote
name)
// git push origin new_branch:master :(this command will be use push a code inside
of one branch to another branch)
// git push -u origin new_branch :( this can will be set a branch to a upstream
form)
// git push --set-upstream origin master :(this command also set a branch to a
upstream)

//NOTE:after set upstream branch you can directly push your code using [ git
push ] command

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------------

13.git Fetch( remote tracking )

// git branch -r :(fetch all remote branch )


// git fetch & git fetch origin :(fetch all update inside a reposetry)
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------------
14.GIT REFLOG (this command can will be use for showing all commit history in a
perticular branch)

// git reflog (branch_name) :shhowing all commit in branch


example :[1] git reflog master
:[2] git reflog master@{1} (this can will be showing all commit before of
this commit

//NOTE : reset also use for doing changes


example : git reset --hard (Has_ID)

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------------------------
15.SET GITHUB ALIAS GLOBALY

// git config --global alias.<alias> <git-command>


// EXAMPLE : git config --global alias.lo "log --oneline"

You might also like