Git Basic Commands : Day 8 of 90daysOfDevops

I am a DevOps Engineer with an aim to learn and contribute to the Tech World!!
📝 Blogging and Sharing: On this platform, I'll be sharing insightful articles, tutorials, and tips on all things DevOps. Expect deep dives into CI/CD best practices, IaC patterns, containerization strategies, cloud optimization, and much more. Let's learn and grow together!
1) git init
This command we use to transform a normal directory to a git local repository
As soon as you hit this command you will see that the .git directory gets created and now your directory will be capable of tracking the changes
2) git clone
git clone is used for cloning the public repository from GitHub to our local
So basically we can get any public repo into our local
$git clone <url of the pulic github repository>
3) git status
git status helps us to know the current status of files whether they are in staging area or they are still untracked files
so if they are untrack so we will use git add to bring the file from untrack to the stage area

4) git log
git log helps to know the recent commit by any other developer on the same branch in which we are working
It will show all the commit message and commit ID with the date and time of the commit

5) git log --oneline
- It is similar to git log but the only difference is that git log --oneline will show the commit ID and only the message so basically it shortens the git log

6) git branch
- It will tell us in which branch we are currently working

7) git branch <branch_name>
It will help us to create a branch from the branch in which we are currently working
Then we can see that the branch we have created is also showing up when we write the git branch

8) git checkout <branch_name>
It will help us to switch to the branch that we want to work upon
Then we can verify by using the git branch
Then you can see that star mark is pointing to the new feature1 branch that we have created so we are currently in feature1 branch

9) git checkout -b <branch_name>
It will help us to create a branch and also switch to that branch
Here -b means branch

10) git add <filename> or git add .
- This command helps to bring all the untracked files to the staging area so that those files can be tracked and committed
Also, we can see red color means untracked files and then we write git add . which will bring all untracked files to the staging area

11) git commit -m < commit message>
This command helps to commit our files so that they are ready to be pushed to the remote repository
And every time we do commit we also pass a commit message so that someone looking at the git log can be aware what the commit is all about

12) git push
git push command helps to push all the committed files /changes to the remote repository
git push origin main
So here origin is the variable type of thing that is holding the location of your remote repository and main is the branch on that remote repo where we want to push our local changes

13) git pull
git pull commands help to pull all the changes from the remote repo to our local repo
git pull origin main

14) git stash
Suppose we are working on one file and suddenly someone asks us to do some more urgent file and we have already done a large number of changes in the file where we are working and it is also not fully complete what we will do in this case that we will git stash it will store our work in a temporary storage known as stash
Also, we can see the list of all the stash afterward to resume working on them by using the git stash list

15) git reset <file_name>
Suppose we have written some code changes in fil1.txt and we have also git add file1.txt
After that, we remembered we did some wrong changes and now in order to bring the file from the staging area to untrack files again we will use git reset <filename>

16) git revert <commit_id>
git revert command helps to undo an existing commit
It does not delete any data in this process instead git creates a new commit with the included files reverted to their previous state so your version control history moves forward while the state of your file moves backward


git reset -> used before commit
git revert ->used after commit
17) git merge <branch_name>
to merge the current branch to the main branch so that all the changes are applicable to the main branch
But we need to be sure that we should be on that branch where we need to merge all other branches
Suppose we want to merge the feature2 branch to the main branch so we first need to be checkout in the main branch and then we can merge the feature2 into the main branch

18) git cherry-pick <commit_ID>
Suppose we want to merge a specific commit only and after that all commits will not be merged only till that cherry-pick commit changes are merged

Thanks,
Amrit Manash
Happy Learning 😊😊
