Little history lesson about GIT
Git was created by Linus Torvalds about 10 years ago. The reason behind creating GIT was he hated doing source control management, imagine your day without version control or source management like, " who coded that and who made changes on that method" Terrible right! so, Linus thought of creating a systematic environment that can take care of changes and code that is made by several of my teammates.
Git has its own learning curve, I faced many problems at the beginning of my programming journey, as nowadays Git is like a global standard like anybody who can code should know Git, and know how to manage code with multiple teammates and should not mess up the whole codebase, cause I've created many issues for my senior teammates but they were very helpful to correct me, and they've explained me the best practices for git, and I'm going to tell you all that.
Repository or (repo) in Git is a collection of files and folders where your whole codebase is located. You can create Unlimited public/private repositories and can create Unlimited Branches.
Branch in Git is the same as you're thinking right now I suppose, Let's take an example of a tree and its branches with leaves.
The repository is like a tree where everything happens where fruit will immerge and grow and at the end, it will ripe.
The branch is for different things happening at a different pace, but everything is related to the tree, for example, you cannot expect to have an apple on one branch and mango on another, cause the tree is of the same codebase, either it will have mango or apple.
you can perform different tasks on different branches of the same repository and both the task will eventually be merged into one sample master branch which is the root of all branches
And lastly, Leaves are the people that are connected to that specific repository and you can have an unlimited number of people (leaves) to your branch Repository.
here are some commands that you'll be going to use at the beginning of any project or any codebase. they are in no specific order
==> Note: The staging area is the area where all the files are ready to be committed
- git clone
git clone " < URL > "
To clone the global repository on your local machine.
- git config
git config —global username “Harshit Saxena”
git config —global.email “firstname.lastname@example.org”
This is to tell git who you are your username, email, address, etc. this information is used during your commits.
- git add
git add < filename >
Files that you want to commit to your repository or ready to be staged
git add --all
To add all the files to the staging area
git add “*.txt”
To add all the text file
git add < directory >/
To add the specific directory to be staged
commit command is used to send your code to your local repository
-m ==> message
git commit -m "write your comment here describing your commit"
- git push
git push origin master
This is used to push your code from the local repository to the Global repository
git pull origin master
To get all the code from the Global repository to your local repository
- To check the status of all the files
- To check the branch that you are working in
git checkout -b < branchname>
- To make a new branch and switch to a newly created one
git checkout < branchname >
- To change the working branch
- To merge different branches to the active branch
- To check all the commits logs
git grep " specific content "
- To search into the working directory "this"
---> These are some commands that will be helpful in your git journey, So in the end I must say to make repositories you will mess up many times but you will learn from your mistakes, that is what really counts. Believe me, I've made mistakes on client repositories in the first week of my job, but learning from your mistakes makes you better at anything. So keep on trying new things.
But try making mistakes on your local repository rather than on the client's repository.
You can find my GitHub profile on my Hashnode Profile.
Git is a very powerful tool for any programmer (experienced / beginner), so I strongly encourage you to get your hands dirty with git. Make a GitHub profile and start coding. Feel free to add your GitHub profile in the comment section. I definitely get back to you with some special tricks that might speed up your process 😉.
Did you find this article valuable?
Support Harshit Saxena by becoming a sponsor. Any amount is appreciated!