# GIT AND GIT HUB
**GIT: WHAT IS GIT?**
This is a distibuted version control system that helps developers to track their codebases, and collaborate with others to manage multiple versions of a project.
**GIT** is decentralized and so you dont need a central server. instead every developer has a full copy of the repo on thier local machine. so that you can role back to a certian version when you need to.
**FEATURES OF GIT**
<ul>
<li>Distributed system</li>
<li>Version Tracking</li>
<li>Collaboration</li>
<li>Branching</li>
<li>Merging</li>
<li>Remote repositories</li>
<li>Extensive Tooling</li>
<li>Staging Area</li>
<li>Speed</li>
<li>Open-Source & Free</li>
</ul>
<hr>
**GitHub: WHAT IS GITHUB?**
**GitHub** is a web-based platform used for version control and collaboration. it hosts repositories and provides an interface to manage your code and other underlying services.
**FEATURES OF GITHUB**
<ul>
<li>Collaboration</li>
<li>Bug Tracking</li>
<li>Feature Requests</li>
<li>Task management</li>
<li>Wikis</li>
</ul>
FIRST of all understand the git workflow
Working Directory
Staging Area
Local Repo
Remote Repo
**THINGS TO UNDERSTAND**
-Initialize a new repository (workig directory)
`.git init`
-Add you files to the staging area
`git add`
To take files to local repo
`git commit `
To take file to remote repo
`git push`
To pull changes back to working directory
`git pull`
To pull a repository for first time
`git clone `
**BRANCHING AND MERGING **
Brancihng alllows you to work on new features or bug fixes without affecting the main codebase. Wheb ready, youu can merge the new code into the main branch
**SETTING UP GIT USING THE TERMINAL (LINUX BASED SYSTEM)**
To set up username
```git config --global user.name "<your_username>"```
to set up email
```
git config --global user.email "<your_email>"
```
To check git branch
`git config --global init.defaultBranch`
To change branch
`git config --global init.defaultBranch main`
**TO OPEN A FOLDER IN VS CODE**
Enter a folder in the terminal and type `code .`
To initialize git repository type `git init`
this would create a hidden folder .git
To check status input
`git status`
To add files to staging area;
Individually
type `git add <your_file>`
All
type `git add .`
To add files to local repo
type
`git commit`
for this command to go through there must be a message
type this command instead
` git commit -m "<anything_you_want_as_a_message"`
To check changes type
`git log`
To push to a repo
`git remote add origin <your_git_link>`
next
`git branch -M main`
To push
`git push -u origin main`
**THINGS TO NOTE**
git pull: To pull from upstream
git clone: get a copy of the full repo on your local machine
git pull:get changes from a repo
git fetch: get latest changes without merging
forking: copy a repository into your own account
**WORKING WITH BRANCHES**
To branch
`git checkout -b <name_of_branch>`
To add branch to stagging area
`git add .`
Then commit to save changes made to branch
` git commit -m "<aded-new feature>"`
then push
`then git push -u origin added-new feature`
To go back to main
`git checkout main`
To check available branches
`git branch`
this would list the branches
to merge you type
`git merge <added-new feature>`
this would merge it to the main branch
then you push
to delete branch
`git branch -d <added-new feature>`
then `git push`
you should be done.....
thanks for visiting