Git and Github Intro.

(1)

git --version

This command is used to see whether git is locally installed in your computer or not

...
git --version

(2)

git init

This command is used to initialize a git repository locally on your computer.

...
git init

(3)

git status

This command is used to see latest changes in the code you have made after the last commit.

...
git status

(4)

git add index.html

This command is used to add index.html file into staging area before commiting.

...
git add index.html

(5)

git add .

This command is used to add all edited files into staging area before commiting.

...
git add .

(6)

git commit -m "your message goes here."

This command is used to commit your latest or recent changes and saves your work with a commit ID and a message.

...
git commit -m "your message goes here."

(7)

git log

This command is used to see history of all your commits.

...
git log

(8)

git diff index.html

This command is used to see latest changes you have made in a file after the last commit.

...
git diff index.html

(9)

git checkout index.html

This command is used to undo the latest changes you have made in a file after the last commit.

...
git checkout index.html

(10)

git reset --hard commit-Id

This command is used to revert to the old commit and also places the HEAD of git to that commit.

...
git reset --hard 41192d2d0ec3e094a46b81c32c035859f7ee7da9

(11)

git reset --soft HEAD@{1}

This command is used to place the head to the last commit in current running branch but the changes in the code are those where we reverted.

...
git reset --soft HEAD@{1}

(12)

git commit -m "reverted to commit-id"

This command is just used to show that we have reverted to old commit.

...
git commit -m "reverted to old commit with commit-id 41192d2d0ec3e094a46b81c32c035859f7ee7da9"

(13)

git branch branchName

This command is used to create a branch named as branchName.

...
git branch branchName

(14)

git branch

This command is used to see all the branches and also tells us which branch is currently running.

...
git branch

(15)

git checkout branchName

This command is used to switch branch from one to another.

...
git checkout branchName

(16)

git merge branchName

This command is used to merge branch named as branchName with the one you are currently working on.

...
git merge branchName

(17)

git branch -d branchName

This command is used to permanently delete a branch named as branchName.

...
git branch -d branchName

(18)

git branch -d branchName

This command is used to permanently delete a branch named as branchName.

...
git branch -d branchName

(19)

create new repository on github

Go to github.com and click on new repository, Give a name to it and click create repository to create a freshy.

...
create new repository on github

(20)

push local repository to remote repository

1) git remote add origin https://github.com/Raza023/GitAndGithubIntro.git
2) git branch -M main
3) git push -u origin main

Use these above commands to push local repository to remote.

...
push local repository to remote repository

(20)

git push on cmd

1) git remote add origin https://github.com/Raza023/GitAndGithubIntro.git
2) git branch -M main
3) git push -u origin main

Use these above commands to push local repository to remote.

...
git push on cmd

(21)

git pull

If you change code on github and commit it right there on github. It will be only there on github but is not mapped on local repository. To reflect those changes in local repository as well you have to run this command.

...
git pull

(22)

fork

Fork someone's github repository in your github account.

...
fork

(23)

clone

1) git clone https://github.com/Raza023/testing.git clonedrepo
2) git remote add origin_clone https://github.com/Raza023/testing.git
3) git push -u origin_clone master

Use first command from above commands to clone repository into your local directory. And after you are done making changes into code, Use other two commands to push those changes into your forked diectory. And then send a pull request to user whom you forked that repository from. He will test your code and will merge it into his own code, if he wants.

...
clone and pull request