Git Configuration:
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.email
git config --global user.name
Create a project on your computer:
mkdir [projectname]
cd [projectname]
to initialize empty Git repository inside your project folder:
git init
to view files inside your project folder:
ls
It will show list of files.
ls -a
To view hidden files(.extension-file) inside project folder.
touch (filename)
To create new/empty file.
It allows us to see the tracked, untracked files and changes.
git status
Add a particular file to the staging area.
git add [filename]
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 the list of commits of 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 hascode]
Git has an area called the stash where you can temporarily store a snapshot of your changes without committing to the repository.
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 branches in a single repository.
git checkout [branchname]
It shows the list of 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 the blog!
link mentioned below for other blog about the introduction of the git.
Introduction to Git
Top comments (1)
Great 👍