Basic Commands "git"
Best practice of git at work. I would like to introduce you some usuful commands
DATE
February 27, 2024
CATEGORY
blog
READING TIME
2 mins
Was your pull requests (PR or MR) take longer time to be approved because you just mix your requests somewhere in pipeline? You accidentally messed up with your code base and git ?
OK, I will share with you some of my experience that I have and I hope it helps!
I remembered when I joined my team, all the seniors and intermediate developers were sharing with me how to use git. My commits are messy and I do not know how to re-base my code base. Therefore, everyone shared their experience on Slack and I also paired with some devs to understand git better. Yes, I did spent 1 week to learn it, you have me now so maybe it is easier to move on.
1. Clone your repo
There are two ways to clone your repo, either through http or ssh. You can look up set up SSH key for git platform and follow instructions. Here is my recommendation: link
2. Git branch and git create new branch
3. Your commit is on the top of others in your local
This is what my team applying to make our repo organized. Basically, after you create git branch and write your code, git graph gonna be like this
Now, if we want our latest commits always be on top of the main so devs can roll back in case there is something wrong. Before edit our code, we can do git rebase main.
If we forgot, eventually, we may have to solve conflicts and then we can do add and commit
After git rebase, we gonna have our git branches organized like this:
4. git add and git commit
Finally, you can do git add and git commit, or git commit -m. Make sure you commit a meaningful messages so your team can understand what you try to do
Alright, I hope you understand your git command better. Next post, I will introduce you some way to fix your branches if you accidentally messed up. Also, I would recommend you post your questions to your team slack so you can learn from your team too. Don't be shy