DEV Community

Cover image for Git Basic Commands That You Need For Regular Project Work
Md. Azad Ul Kabir
Md. Azad Ul Kabir

Posted on

Git Basic Commands That You Need For Regular Project Work

I am trying to list some commands above the work criteria. Check this below

Git Initial Command:

1. git init
2. git status
3. git --version
4. rm -rf .git  //Remove git folder
5. git status -s
Enter fullscreen mode Exit fullscreen mode

Git Configuration Command:

1. git config --global user.name "username"
2. git config --global user.email "email"
3. git config --list
4. git config --global alias.last "log -p -1"  //Create alias for shortcut
Enter fullscreen mode Exit fullscreen mode

Git File Add Command:

1. git add .   //Stages new and modified file without deleted file
2. git add -A  //Stages all file
3. git add -u  //Stages modified and deleted file without new file
Enter fullscreen mode Exit fullscreen mode

Git Commit Command:

1. git commit -m "messeage"
2. git commit -a -m "message"  //Stage file commit without add
3. git commit --amend          //Change the last commit
Enter fullscreen mode Exit fullscreen mode

Git Commit Log Command:

1. git log
2. git log -p -2
3. git log --stat
4. git log --pretty=oneline
5. git log --pretty=short/full
6. git log --pretty=format:"%h 00 %ae"
7. git log --since=2.days/weeks/months/years
Enter fullscreen mode Exit fullscreen mode

Git Branch Command:

1. git branch
2. git branch `branchName`
3. git checkout `branchName`
4. git merge `branchName`                 //Branch must be master
5. git branch -v
6. git branch --merged
7. git brach --no-merged
8. git branch -d `branchName`             //Locally deleted
9. git push origin --delete `branchName`  //Deledted on github
10. git checkout -b "branchName"          // Create brach and switch to the created branch
Enter fullscreen mode Exit fullscreen mode

Git Compare Command

1. git diff `fileName`           //Difference tracked file code between last commit file to now
2. git diff --staged `filename`  //Difference Stages file code between last commit file to now
3. git reset `fileName`          //Stages file to unstages file
4. git checkout `fileName`       //Clear file to last commit
5. git checkout -f               //For all file
6. git rm --cached `fileName`    //Tracked file to Untracked file
Enter fullscreen mode Exit fullscreen mode

Git Command For Github

1. git remote add origin `url`
2. git remote rm origin
3. git push -u origin master
4. git pull origin master
5. git remote -v
6. git clone `url`
Enter fullscreen mode Exit fullscreen mode

Git Extra Command

1 .gitignore
2. git rm `fileName`
3. git mv `fileName1` `fileName2`  //Change the filename & fileName2 is changed name.
Enter fullscreen mode Exit fullscreen mode

NOTE: If you don't understand any command, find out on Google. This way you can learn about git commands properly and have a crystal clear idea on git commands. Keep exploring.

Top comments (0)