Hi 👋🏻
If you just begin your Git Journey and confused😕 with Git Commands ,Then this is for you ☺️!
Environment setting for Git Bash
If you don't know Git Bash or if you haven't used git in your machine 💻 , follow these steps to get started:
1.Download Git Bash for your device 💻 Git Bash
2.Open Git Bash by clicking the right mouse button 🖱️ for Windows user. Then set up your name📛 and email📧 ID:
$ git config --global user.name "<Your_Name>"
$ git config --global user.email "<Your_Email>"
3.Go to GitHub and create your GitHub account using your email.
Make sure ,to use the same email📧 ,you have used earlier.
At this instance there are two ways to go furthur:
1️⃣First
4.Go to your desired folder📁 your you want to keep all your your GitHub repository😳.
clone a remote repo. via URL
git clone URL
You may get URL from a online GitHub repository by Clicking on Code
Button 🌛 of Your repository.
2️⃣Second
4.Go to a folder📁 which you want to make as a GitHub repository😳.
Initalize a existing directory as a git repo.
git init
That's all for setting ,Now begin your Code
🎉🎉Commands🎉🎉
1 :
Below will add your modified file.
git add myFile
When you want stage your changes for myFile file.
git add . Or git add -A
When you want stage your All modified file.
2 :
Below will restore your file.
git reset myFile
unstage a file while retaining the changes in working directory
Below will show all commits with all details like author and their email.
git log
Below will show commits in compact way!,Only show commit hash and message
git log --oneline
3 :
git revert <commit hash>
If you want roll back your commit,You may use above command.
you can get commit hash of all of your commit by entering command: git log
4 :
Below will show your current status.
git status
If you haven't staged or add it ,It will show like this
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: abcd.md
no changes added to commit (use "git add" and/or "git commit -a")
If you have staged your file. Then, It will show you staged modified file for your next commit.Like this:
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: abcd.md
5 :
git push origin <branch>
When you want to push your final changes to remote repository in particular branch.By default ,you have master branch ,so you may
write as:
git push origin master
6 :
git pull
When you want to pull all changes from remote repository in your current local branch.
7 :
When you want to create branch
git branch branch1
create a new branch name branch1 at the current commit
When you want to see all branches
git branch
It will list your branches. And a * will appear next to the currently active branch like this:
PS D:\winter plan> git branch
* branch1
master
one
When you want to switch branch
git checkout branch1
switch to another branch1 and check it out into your working directory
8 :
Merge a branch into another or main
git merge branch1
merge the branch1 history into the current one
When you want to switch branches either you need to commit your modified changes Or you may temporarly stored modified and tracked file.
git stash
above command Save modified and staged changes and below will discard the changes from top of stash stack
git stash drop
Top comments (0)