Git & Github (Harry)

1/1/1970

Git & Github (Harry)

Git & GitHub Tutorial For Beginners In Hindi

Git

Git is a powerful and popular version control system that enables effective tracking of changes in source code.

Why use Git ?

70% of developers worldwide use git for development. Reasons:

[Untrack]        [Unmodified]     [Modified]          [Stage]
    |                 |                |                 |
    |------------------Add File------------------------->|
    |                 |                |                 |
                      |-Edit the file->|                 |
    |                 |                |                 |
    |                 |                |-Stage the file->|
    |                 |                |                 |
    |<-Remov the file-|                |                 |
    |                 |                |                 |
                      |<------------Commit---------------|

In Git, files in repository can be classified into four different states.

Git Commands

git init
git status

red color - untracked files , Green color - Staging area

git status -S # short/simple

First Column (Staging Area): A(New file added), M(Modification), D(Deleted), R(Renamed) Second Column (Working Tree): M(Modified), D(Deleted)

git add
# or
git add -A # --all
git add index.html
git commit #open in vim editor
git commit -m "This is my first commit"
git commit -a -m
# automatically stage any modified or deleted files(but not new, untracked file) and creates a commit with specified messages.
git rm waste.html # remove
git rm --cached waste.html # remove

More

git checkout -f # --force
git checkout about.html
git log
git log  -p -1 # --patch, -1: no of last commit to see
git diff # difference
git diff --staged
clear
:q

what - and -- in git?? -: represents options in git command --: separate options from arguments explicitly

Non Git but useful commands (Unix features)

ls
touch about.html

create .gitignore file

touch .gitignore

add files inside .gitingnore file manually or:

Add index.html into the .gitignore
git rm --cached index.html # file will be removed from the staging area
# or
echo "index.html" >> .gitignore
# or
printf "index.html\n" >> .gitignore

verify ignored files.

cat .gitignore

Note: Git Bash can be used as Unix terminal

Branch

git branch feature1
git branch

Green - Show that you are in this branch, White color - other branches

git checkout feature1
# or 
git switch feature1
git checkout -b feature2
#or
git switch -c feature2 # --create
git checkout master
git merge feature`

Note: When you switch branches in git, it will remove any uncommitted changes that conflict with the target branch. This is safety measure to prevent potential data loss. However, switching branches would not delete untracked file in repository.

Github

Github is a hosting service for git repositories and if you have a project hosted on Github, you can access and download that project with commands on any computer you have access and make your changes and push the latest version back to Github. Github allows you to store your repo on their platform. It is also comes ability to collaborate with other developers from any location

git remote add origin https://github.com/gauravmeee/git-in-one-video.git
git remote 
git remote -v # verbose : additional infor about remote repos, including fetch and push URIs
git push origin master
git push -u origin master # --set-upstream
git pull -u origin master

Note: The -u flag stands for --set-upstream. This sets the upstream tracking relationship for your local master branch to the origin/master branch. git push and git pull commands can be used without specifying the remote branch because Git will remember the upstream branch.

git push
git pull
git clone https://github.com/gauravmeee/markdown-notes.git
git clone https://github.com/gauravmeee/markdown-notes.git Folder1

More Remote Commands

git clean # Remove untracked files from working directory
 
git commit --amend # let you amend the most recent commit
 
git fetch # fetching downloads a branch from another repository, along with all of its associated commits and files.
 
git pull # Pulling is the automated version of git fetch
 
git reset # undoes changes to files in the working directory (that are not pushed)
 
git revert # Undoes a commit snapshot
 
git rebase # let you move branches around, helping avoid unecessary merge commits.
 
git reflog # git keeps track of updates to the tip of branches using a mechanism called reflog