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

Git&Github

This document provides an overview of Git and GitHub, detailing installation, setup, and essential commands for version control. It covers basic commands, workflow, branching, merging, and resolving conflicts, as well as undoing changes. The cheat sheet serves as a quick reference for users to effectively manage their repositories and collaborate on projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Git&Github

This document provides an overview of Git and GitHub, detailing installation, setup, and essential commands for version control. It covers basic commands, workflow, branching, merging, and resolving conflicts, as well as undoing changes. The cheat sheet serves as a quick reference for users to effectively manage their repositories and collaborate on projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

GIT & GITHUB

Git is the free and open source distributed version control system that's
responsible for everything GitHub related that happens locally on your
computer. This cheat sheet features the most important and commonly
used Git commands for easy reference.

INSTALLATION & GUIS


With platform specific installers for Git, GitHub also provides the ease of
staying up-to-date with the latest releases of the command line tool while
providing a graphical user interface for day-to-day interaction, review, and
repository synchronization.
GitHub for Windows - https://windows.github.com

SETUP
Configuring user information used across all local repositories
git config --global user.name “[firstname lastname]” - set a name
that is identifiable for credit when review version history
git config --global user.email “[valid-email]” - set an email address
that will be associated with each history marker
git config --list - lists all the details you have inputed
# git –version - gives the version of github you are using

BASIC COMMANDS IN GIT


cd (filename) - change directory to go into particular folder
cd .. - go out of directory
ls - to check the flies within the opened folder ,it will list the elements
ls -a - to check all the files like hidden files
git status - displays the state of the code .
TYPES - change(modified) , new file(untracked) , add(staged) , commit
(unchanged)
#WORKFLOW - GIT repo(create) -->clone --
>changes -->add -->commit --
>Initialize -->push

CLONE &INIT
Configuring user information, initializing and cloning repositories
git init - initialize an existing directory as a Git repository
git clone [url] - retrieve an entire repository from a hosted location via
URL

ADD &COMMIT
git add <- file name -> - adds new or changes files in your working
directory to the git staging area.
git commit -m “some message to signify the changes” - it is the
record of the change.

PUSH COMMAND
git push -u origin main - here by default all repo in our git
hub are remote repo among from them .A specific default repo is
picked .AND THAT default repo is origin .within this orgion we are referring
to the branch named main.

Init command (local project ko remote main dalne ke liye)

mkdir <-file name -> - to make new directory (subdirectory) within


the folder
git init – used to create a new git repo from local repo
git remote add origin <-link-> - to add new repo within the git hub
whose name would be origin
git remote -v - identifies the repo you are on. to verify the remote we
are talking about exist by showing all the repo
git branch - to check branch we are on
git branch -M main - to change the name of the branch we are on by
naming it main
git push -u origin main - here -u sets the upstream , while working on
the same project we do not use -u it by defaults makes all the changes to
origin repo which has a branch main.

GIT BRANCHES and COMMANDS


Git branch - to check the branch you are on
Git branch -M main - to rename the branch you are on to main
Git checkout <- branch name-> - to exit the current branch you are
on and go to existing branch name
Git checkout -b <- new branch name -> - to create a new branch
Git branch -d <- branch name -> to delete branch

MERGE CODE
(merging 2 branches into 1 branch could be like applying the changes
recommended by jr coder into the main branch by senior developer)
WAY 1
git diff <-branch name-> - to compare commits, branches, files &
more (put the name of the branch you want to compare with the branch
you are currently on)
git merge <-branch name -> - to merge 2 branches (do this by going
onto the branch whose changes you want to apply from & put the name of
the branch you want to add it to)
git push - to push the changes you have made over to remote
WAY 2
Create PR( pull request) – lets you tell others about changes you’ve
pushed to a branch in a repository on github.
Click on Compare &Pull request(branch u are on) - -> SHOWs which
branch u are copying from and branch you are copying to  add
comment  create new pull request  (github checks whether it can
automatically merge or whether it has some conflicts in there)  Click on
MERGE PULL REQUEST confirm merge  confirm pull request is formed
and ust be selected.
#to apply this changes from remote(github) to local , we use pull
command
git pull origin main - used to fetch and download content from a
remote repo and immediately update the local repo to match that
cantent.

RESOLVING THE MERGE CONFLICTS


An event that takes place when git is unable to automatically resolve
differences in code between two commits.

UNDOING CHANGES
Case1 : staged changes (ADD CHANGES not commited yet)
git reset <-file name-> - file names will havethe name of the file
you want to undo changes from
git reset - FOR all the undoing all the changes
Case2 : commited changes (for those who are commited once)
git reset HEAD-1 - ALL Commits are stored within the git .HEAD
refers to the latest commit you have made . head-1 refers to going one
commit back
Case3 : commited changes (for when we want to go multiple commits
back)
git reset <-commit hash -> - All commits have their particular
hash, with reset it goes back to intial commits before you made any
commits
git reset –hard <-commit hast-> -

FORK

You might also like