Git Congiguration
git config --global user.name “Your Name”
Set the name that will be attached to your commits and tags.
git config --global user.email “you@example.com”
Set the e-mail address that will be attached to your commits and tags.
To view the configuration
git config --global user.name
git config --global user.email
Starting a project
Create a project on your computer
mkdr [project name]
cd [project name]
To initialize empty git repository inside the project
git init
To view hidden files(.extension) inside the project folder
ls -a
To view inside the hidden .git file
ls .git
To create new empty file
touch [filename]
It allows us to see the tracked,untracked files and changes
git status
Adding a particular file to staging area
git add [filename]
Adding all the files to the staging area from current directory down into the directory tree.
git add .
Create a new commit from changes added to the staging area.
The commit must have a message!
git commit -m "Message"
It shows history of commit of the current branch
git log
To unstage your file/Removing changes from staging area
git restore --staged [filename]
To remove a commit from the history of a project
git reset commit_hashnode
Git has an area called the stash where you can temporarily store a snapshot of your changes without committing to the repository.
Put current changes in your working directory into stash for later use.
git stash
Apply stored stash content into working directory, and clear stash.
git stash pop
Delete a specific stash from all your previous stashes.
git stash drop
Connect remote repository to local repository by using this command
git remote add origin url
Pushing local changes to remote repository
git push origin master /
git push -u origin master
A fork is a rough copy of a repository. Generally forking a repository allows us to experiment on the project without affecting the original project
Reason for forking the project
1.propose changes to someone else's project
2.Use an existing project as a starting point.
Cloning the forked project to local
git clone url
After cloning you will be able to see clone project inside your project folder
upstream : upstream generally refers to the original repository that you have forked from other git repositories.
git remote add upstream url
for viewing both url(origin and upstream):
git remote -v
create new branch
git branch branchname
The git checkout command switched branches or restores working tree files. It allows switching between multiple features/branches in a single repository.
git checkout [branchname]
It shows the list of the branches
git branch
Why we create new branch?
=>Because we want to open a new pull request and we can only open a new pull request with a new branch. In simple language one pull request means one branch.
Never commit on main branch and create our pull request first.
Conclusion
That's a wrap!! You 've made it to the end of this blog!
Follow me on twitter for more such contents
Top comments (2)
Congratulations Shristy on your first blog
Congratulations 👏🏻🥳