Diary TOGit and Github

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Today I learned that I have to create a repository then I had

to add my project or files there.


Then I need to create new branch. Then all the updated of
the project will be uploaded there then I will get a pull
request.
Verify the Pull request then merge it. And It will directly
reflect to main branch (You can see at upper bar from which
branch to branch you are merging it.)
git init
git add <folder1> <folder2> <etc.>
git commit -m "Your message about the commit"
git remote add origin
https://github.com/yourUsername/yourRepository.git
git push -u origin master
git push origin master

$ git config --global user.name krishnachaudhary-8469


$ git config --global user.email
krishnachaudhary596@gmail.com

Stagging area is a place where we put out files to commit.

Commit is a snapshot, meaning git has recored your file.


Now commited files are Unmodified, means there is no
changes
done in it.
But if you edited the file then that file should again go to the
staged area so that it should be commited(git
snapshot(record)).

If you have removed any file then that file will go the
untracked are.
It should be staged even it's deleted then commited Then git
will not record it anymore.

git add:(For stagging area)

git commit -m "Message": What changed you have made and


everything has been set(takes snapshots).
Commit only when you are ready with your changes. A valid
changes.

git checkout <file name>: This will restore you file in


previously commited stage.
git checkout -f: This compare all the files with last commited
stage and restore it.
git log: This will all the commits and commited message, so
that you can check what changes
you have made.

git diff: This will compare Working tree with staging area.
Means last changes vs current changes.
Remember you have not used git add(For adding the files to
stagging area), once you used git add
with latest changes there will be no difference to show.

git diff --staged: If you want to compare staging area with last
commit.

git commit -a -m "skipped staging area and fixed(git add):


In this command we skip staging area (git add(only used once
then can be skipped)
directly go for commit.(It's not recommended)

git rm <file_name>: removes file from working directory(hard


drive) and staging area.
git rm --cached <file_name>: removes file only from staging
area and remains in working directory(hard drive).
It is helpful when you have added unrelevant file to the
staging area(git add) and now you want to remove it.
After that use git commit for taking snapshot of the changes.

git status -s: This command gives status in a summaried way.


Very helpful when you have so many files.

touch .gitignore: If you want to ignore any file on git


repository then create git ignore file and add those
file names which you want to ignore(It will ignore that file
from everywhere).

<folder name>/: this will ignore entire folder.


*.<extension> : this will ignore all the files with given
extension.
/<filename>.<extension> : this will ignore only mentioned file
which is mentioned in git ignore file.

git branch <new branch name>: creates new branch.

git checkout <branch name>: switch to branch.

Important: suppose there are two branches named as


main/master and feature. So if you have made any changes
on
feature branch then it will not reflect to the main branch
untill you merge it. Be carefull before merging it.
So this way you can work on any project without
affection the actual project on main branch.

So make sure you create an new branch and work on it


then verify it once then merge it to the main branch.

git merge <branch name(feature1)>: This command will


merge the operations of working branch(feature1) to the
main
branch.

git checkout -b <branchname>: Create and switch to the


newly created branch.

Github: It is a hosting service for git repository.

git remote add origin url: means the url has been names as
origin.

git remote -v: show the URLs that Git has stored as a short
name(origin)
gti push origin master: means push the origin to master
branch.

You can push any number of branches to the github.


Suppose you have created a new branch now if you
have pushed some files in master branch.
Now you pushed the same files to the feature1(branch)
you will get notification on github i.e. "Compare and Pull
request"

You might also like