Skip to content

Latest commit

 

History

History
215 lines (155 loc) · 4.09 KB

File metadata and controls

215 lines (155 loc) · 4.09 KB

Git and GitHub

Git

Version Control System is a tools that helps to track chnages in code. Git is a version Control system

It is popular for

  • free and Open Source
  • Fast and Scalable

It is used for track the history and collaborate.

Github

Website that allows developers to store and manage their code using it.

https://github.com

Some Keywords

  • Commit means change in github
  • ~ it means you are in root directory

Task

1. Create a new respository
2. Make our first commit

Configuring Git

git config --global user.name "myname"
git config --global user.email "xyz@b.com"
git config --list

Clone and Status

Clone - Cloning on our local Machine

git clone <Link>

Status - Displays the state of the code

git status

M in VS code means - Modify

U in VS code means -Untracked

Untracked - New files that git donesn't yet track
Modified - Chnaged
Staged - Files is ready to be committed
Unmodified - Unchnaged


Quick Knownledge

To Show all file in current directory

ls -a

Add & Commit

add - Add new or changed files in your working directory to the git staging area.

git add <file name >
For adding all files in one

git add .

commit - It is the record of chnage

git commit -m "some massage"

here m for massage 

Push Command

push - Upload local repo (folder/file) to remote repo

git push origin main

,here main is branch
flowchart LR
A[Untracked] --> B[Add]
B --> C[Commit]
C --> D[Push]
Loading

Init Command

Init - used to create a new git repo

When we make a new folder then you have initilise it first.

git init
git remote add origin <link>
git remote -v (to verify remote)
git branch(to check branch)
git branch -M main(to rename branch)
git push origin main

git push -u origin main
here, u mean upstream you dont need to say again n again origin main.
so from the next time just use 

git push
flowchart TB
A[Create new repository in Github] --> B[Create folder in local machine and open with VS code ]
B --> C[git init]
C --> D[git remote add origin .... ]
D --> E[ git add .]
E --> F[git commit -m ....]
F --> G[git push origin main]
Loading

Git Branches

Git Branches

Branch Commands

git branch  (to check branch)
git branch -M main (to renmae branch)
git checkout < branch name > (to navigate)
git checkout -b <new branch name > (to create new branch)

git branch -d <branch name > (to delete branch)

Merging Code

Way 1

git diff < branch name > (to compare , commits ,branches , files and more)

git merge <Branch name > (to merge 2 branches)

way 2

to Create a pull request

Pull request - It tells you others about chnges you 've pushed to a branch in a repositoey on Github.

Pull command

git pull origin main

used to detch and download content from a remote repo and immediately update the local repo to match that content.

Resolving Merge Conflicts

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

Undoing Chnages

Case 1 : staged changes

git reset <-file name->
git reset

Case 2 : Commited changes (for one commit)

git rese HEAD~1 => HEAD 1 is our latest commit

Case 3 : Commited changes (for many commits)

git reset<-commit hash-> => To reset more  commit

git reset --hard <-commit hash-> => Chnage in VS code too

To see all commit use

git log

and q for quit

Fork

A fork is a new repository that shares code and visibility settings with the originak "upstream repository"

Fork is rough copy