All About Shopping Oops GIT

Git is a software that allows you to keep track of changes made to a project over time. Git works by recording the changes you make to a project, storing those changes, then allowing you to reference them as needed.

Here some reference to understand better!!

So it’s all about shopping..!! I mean GIT :)

So here Shopping → Git

Clothes → Code

Buy Clothes → Write code

My wardrobe → Master

Temp branch → Temporary wardrobe

Let me help you out to my best for understanding Git commands.

I was going MUMBAI,I have so many clothes!

But I don’t have wardrobe so I buy a new wardrobe using git clone “my wardrobe”,Consider my wardrobe as Master

I like to keep my wardrobe master clean and only put clothes (code) which I am sure of in my master that’s why before putting to my Master wardrobe I create branch “Temporary Wardrobe” using

Git branch -b “Temporary wardrobe”

In this I can put anything I want and do experiments,whenever I put clothes to the wardrobe I usually check the status using git status.

When I buy clothes( I write code ) and when I am done, I put it to Temporary wardrobe branch first.

So first thing is git status which tells me all the clothes I have bought then I do git add — — all because I want to add all new clothes to my temp wardrobe.

Then I forget always why I bought for it the purpose when I want so I put meaning message on sticky note And make a commitment with my clothes by Git commit -m “wow my jeans and top”.

Now listen, I have all my clothes on my branch Temporary wardrobe and I am not sure of these clothes so I will push to my wardrobe using git push -u origin master But no, we don’t push to master directly(Remember master has to be clean thing I told you)

So I will push these clothes to my Temporary wardrobe branch first using

git push -u origin Temporary wardrobe

Now I feel comfortable with these clothes so I will put it in my master by creating Pull request and merging my Temporary Wardrobe branch with master “git merge Temporary Wardrobe”

I don’t need this branch anymore so I will delete it using git branch -D Temporary Wardrobe

and create another branch when I will go for shopping again yayaya

I will keep doing shopping and whenever I do I create branch each time and first put it in my branch and then merge it with master, after doing shopping for some time my wardrobe looks like this (just don’t be jealous of my clothes :P )

Some more fun:

Sometimes my sister puts some clothes in My wardrobe Master which I am not aware so every morning the first thing I do is git pull — rebase origin master to pull and see all the changes done in my master

Sometimes I create branch and keep doing masti and commit multiple clothes one by one like:

Git commit -m “Bought jeans hahaha”

Git commit -m “Bought sexy clothes ummm”

Git commits -m “clothes for marriage”

When I go git log it looks like this

“Bought jeans hahaha”

“Bought sexy clothes ummm”

“clothes for marriage”

Now it doesn’t look good and I want to make all this as one commit so what I do is

git rebase -i HEAD~3

Because I want to merge last 3 commits into one and then what I see is

“Bought jeans hahaha

Bought sexy clothes ummm

clothes for marriage”

Still the commit message looks messy so I can update my last commit message using git commit — amend

And I make it as “Clothes for marriage”

Any time I do rebase my branch with master after that I have to do git push -f origin <your private branch> to forcefully push all the clothes to my branch

Pheww Finally done!

All Set!! :)

Some more information

Delete the most recent commit, keeping the work you’ve done:

git reset — soft HEAD~1

Delete the most recent commit, destroying the work you’ve done:

git reset — hard HEAD~1

Different between old and new comments

git diff HEAD

Hope that help you,

Happy coding!!