If you just begin your Git Journey and confused😕 with Git Commands ,Then this is for you ☺️!
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.
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.
4.Go to a folder📁 which you want to make as a GitHub repository😳.
Initalize a existing directory as a git repo.
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.
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.
Below will show commits in compact way!,Only show commit hash and message
git log --oneline
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:
Below will show your current 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
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
git push origin master
When you want to pull all changes from remote repository in your current local branch.
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
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
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.
above command Save modified and staged changes and below will discard the changes from top of stash stack
git stash drop