Git and GitHub

Why is Git and GitHub

Git

GitHub

Version Control In a Team:

Suppose you're writing code in your laptop. And some how the file gets deleted.

Or you and your friend are working together on a project, and there's a card component, your friend was adding 5px borders to the card, you didn't know what he is working on, and you added drop-shadow around the card. Means both of you are modifying the same part of code: css of the card.

Version Control As Individual Developer: 

Suppose you designed a card with border, padding, margin and drop-shadow. It was looking awesome.

Now, you wanted to go a step further, and make it glassmorphic with animation, you tried with a few rules, but couldn't succeed now you want to remove all the code you added for this, and want your initial simple card back.

You can do this with Git, in just one command:

git stash.

What is Git and GitHub

Git

GitHub

  • Git is a CLI or Terminal Tool
    CLI (Command Line Interface)
  • It is written in C language.
  • It is used for Version Control of your Code or any other file/folder.
  • It does not has any UI, it is used from the command terminal itself.
  • Github is simply a Website, built using web development languages and framework, like Ruby and Ruby on Rails
  • As Git offers Version Control on your local machine, GitHub offers the same on a cloud/Website, so that you can share your code for others to work on it as well.

What is Git and GitHub

What is Git and GitHub

Git
local operations

  1. Start Tracking on your local machine:
    Open terminal on any Folder that you want to track changes in, and run the following command.
$ git init

.gitignore file
Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore

you can add a .gitignore file at the root of your folder to exclude files, folders that you don't want to be tracked.

What is Git and GitHub

  1. Once the tracking starts, changes are at 3 level:
    U - untracked - files which are newly created, or added in the folder
    M - modified - existing files with changes
    D - deleted - existing file deleted

Git
local operations

What is Git and GitHub

Snapshots the file in preparation for versioning

$ git add [file]

$ git add .
// git add all
$ git commit -m "[descriptive message]"

Records file snapshots permanently in version history

Git
local operations

What is Git and GitHub

$ git reset [commit-hash]

Undoes all commits after [commit], preserving changes locally

$ git reset --hard [commit-hash]

Discards all history and changes back to the specified commit

Git
local operations

What is Git and GitHub

$ git stash
Stash/Removes all the active changes

$ git stash apply stash@{0}
Re-Apply the stash at the index (0) back to the branch


$ git stash pop
Re-Apply all the stashed changes to the branch

Git
local operations

What is Git and GitHub

$ git log
Lists version history for the current branch


$ git log --follow [file]
Lists version history for a file, 
beyond renames (works only for a single file)


$ git diff [first-branch]...[second-branch]
Shows content differences between two branches


$ git show [commit-hash]
Outputs metadata and content 
changes of the specified commit

Git
local operations

What is Git and GitHub

$ git branch [branch-name]
Creates a new branch

$ git merge [branch-name]
Combines the specified branch’s history 
into the current branch.


$ git branch -d [branch-name]
Deletes the specified branch


$ git checkout -b [branch-name]
Switches to the specified branch 
and updates the working directory

Git
local operations

What is Git and GitHub

$ git config --global user.name "[name]"
Sets the name you want attached 
to your commit transactions


$ git config --global user.email "[email address]"
Sets the email you want attached 
to your commit transactions

$ git config --global user.email "[email address]"
Sets the password PAT you want attached 
to your commit transactions


$ git config --global color.ui auto
Enables helpful colorization 
of command line output

GitHub
remote operations

What is Git and GitHub

$ git remote add origin [url]
Specifies the remote repository for your 
local repository. 
The url points to a repository on GitHub.


$ git clone [url] = git init + git remote add origin [url]
Clone (download) a repository that already
exists on GitHub, including all of the files, 
branches, and commits

GitHub
remote operations