# Git and Github for beginners.

# Linus Torvald.
The Man behind Git. He created this Masterpiece in 2005 for the development of the Linux kernel.

![Torvalds.webp](https://cdn.hashnode.com/res/hashnode/image/upload/v1658742462971/PU7oMSFsM.webp align="left")


# Git.
Git is a tool that is used for **source code management**. It is used in the software industry and it's an ****open-source**** **version control system** used to handle massive projects.

Git is a brilliant tool it tracks your all files and their records as well as who makes changes in which parts
of the project. It enables multiple developers to collaborate and work together as a team.
No matter where you are from working and which part of the country it helps you to work on the same projects yes, absolutely it is a powerful tool.

During software development programmers collaboratively develop source code. It provides robust speed, data integrity, and support for distributed non-linear workflows. 


![well-done-despicable-me.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1658743826344/CfIXYIybS.gif align="left")

## Installation.

### Search download git.


![git.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658744465575/sH8U3_o3h.PNG align="left")


### Download for Mac, Windows.......


![git dn.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658744598758/iRZUscrF-.PNG align="left")

> After installation.............


### Go to the project folder.

The project on which you work or want to upload on Github.


![tsla.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658746201951/Qb4MgIq4u.PNG align="left")


> After this Git is ready to play..



## Setup.


### *New users*

Enter your username and Email.


```Git
$ git config --global user.name “Your Name”
``` 
Set the name that will be attached to your commits and tags.


```git
$ git config --global user.email “you@example.com”
``` 
Set the e-mail address that will be attached to your commits and tags.


```git
$ git config --global color.ui auto
``` 
Enable some colorization of Git output.


## working on the project.

### *Initialize*


```git
$ git init [project name]
``` 
Create a new local repository. If [project name] is provided, Git will
create a new directory name [project name] and will initialize a
repository inside it. If [project name] is not provided, then a new
repository is initialized in the current directory.

```git
$ git rm [file]
```
Remove file from working directory and staging area.
```git
$ git stash
```
Put current changes in your working directory into stash for later use.
```git
$ git stash pop
```
Apply stored stash content into working directory, and clear stash.
```
$ git stash drop
```
Delete a specific stash from all your previous stashes

## Most Important in Git.
 
```
$ git status
```
Displays the status of your working directory. Options include new,
staged, and modified files. It will retrieve branch name, current commit
identifier, and changes pending commit.
```
$ git add [file]
```
Add a file to the staging area. Use in place of the full file path to add all
changed files from the current directory down into the directory tree.
```
$ git diff [file]
```
Show changes between working directory and staging area.
```
$ git diff --staged [file]
```
Shows any changes between the staging area and the repository.
```
$ git checkout -- [file]
```
Discard changes in working directory. This operation is unrecoverable.
```
$ git reset [file]
```
Revert your repository to a previous known working state.
```
$ git commit
```
Create a new commit from changes added to the staging area.
The commit must have a message!

## To check what you do.

```
$ git log [-n count]
```
List commit history of current branch. -n count limits list to last n
commits.
```
$ git log --oneline --graph --decorate
```
An overview with reference labels and history graph. One commit
per line.
```
$ git log ref..
```
List commits that are present on the current branch and not merged
into ref. A ref can be a branch name or a tag name.
```
$ git log ..ref
```
List commit that are present on ref and not merged into current
branch.
```
$ git reflog
```
List operations (e.g. checkouts or commits) made on local repository


## ignoring files.

 What it means by ignoring-
> Sometimes

what happens if you want to upload your project or some work you merge on a certain branch you don't want that some of the images and other stuff is uploaded on my repository or in the project so, this help in this....


![images.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1658748755870/4icKFAsw9.jpg align="left")

### *and need to do this*


- Go and create file

```
.gitignore
``` 
inside this use, you need to understand what things you don't want to upload and to do this there are some characters to add in ignore file. These are here 


```
$ cat .gitignore
/logs/*
!logs/.gitkeep
/tmp
*.swp
```

Verify the .gitignore file exists in your project and ignore certain type
of files, such as all files in logs directory (excluding the .gitkeep file),
whole tmp directory and all files *.swp. File ignoring will work for the
directory (and children directories) where > .gitignore file is placed.


![images (1).jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1658749218243/ckAhAfLHD.jpg align="left")




![social.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1658749665717/Ecvz2x80c.jpg align="left")

# Github.

GitHub is a Git repository hosting service, but it adds many of its own features. While Git is a command line tool, GitHub provides a Web-based graphical interface. It also provides access control and several collaboration features, such as a wikis and basic task management tools for every project.


## Fork, pull request and merge


 are make GitHub so powerful. Gregg Pollack of Code School (which just launched a class called TryGit) explains that before GitHub, if you wanted to contribute to an open source project you had to manually download the project’s source code, make your changes locally, create a list of changes called a “patch” and then e-mail the patch to the project’s maintainer. The maintainer would then have to evaluate this patch, possibly sent by a total stranger, and decide whether to merge the changes.



![66-661696_superman-icon.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658750076253/HbnQvlle0.png align="left")


## Go to github.com

[github](https://github.com/)


- Create your account✔

- Enter username✔Choose wisely

- Enter Email✔

- Password ✔


## Create new repository on Github

You can create a new repository on your personal account or any organization where you have sufficient permissions.


 
- 
Log into the GitHub administrative console
 
- 
Move to the GitHub Repositories page
 
- 
Click on the green “New” button
 
- 
This will bring up the GitHub repo creation wizard
 
- 
Enter the name of the GitHub repository


- Include a description (optional)


- Choose to make this a public or private GitHub repository


- Add a README (optional)


- Click the green “Create Repository” button to finish the process.



## Steps to upload the project on Github using Git.

### Go to the project folder.

The project on which you work or want to upload on Github.


### Enter your username and Email.

```Git
$ git config --global user.name “Your Name”
``` 
Set the name that will be attached to your commits and tags.


```git
$ git config --global user.email “you@example.com”
``` 
Set the e-mail address that will be attached to your commits and tags.

```
$ git init [project name]
```
Create a new local repository. If [project name] is provided, Git will
create a new directory name [project name] and will initialize a
repository inside it. If [project name] is not provided, then a new
repository is initialized in the current directory

```
$ git add [file name]
```
Add a file to the staging area. Use in place of the full file path to add all
changed files from the current directory down into the directory tree.

```
$ git status
```
Displays the status of your working directory. Options include new,
staged, and modified files. It will retrieve branch name, current commit
identifier, and changes pending commit.

```
$ git commit -m "message"
```
Create a new commit from changes added to the staging area.
The commit must have a message!


```
git remote add origin https://github.com/yourusername/your-repo-name.git
```

enter your repo name here


```
git remote add origin ...
``` 


```
git push -u origin master
``` 

ALL SET













