Git and GitHub
Git is a tool used by many developers and also people contribute to the open source projects using git. Git is a version control system. All the developers use git.
What is GIT
Git is free and opensource. It is a distributed version control system. It tracks any changes made to the files and allows us to revert to the older version of the files. This allows us to revert to the older code if we have encountered any bugs or any issues. Many people can work on the same project and contribute their respective code without any issues of missing any files.
Conventional commits and other Git best practices
When you use git, remember that you are using to make it easy for other developers. Git best practices are important because you work with other people and they need to understand what are the changes done by you and the reason for those changes.
Make sure that you commit your code regularly. It is better to commit the code in small clusters when an issue is fixed or a task is completed than waiting to commit mutliple issues fixes at a time. It is better to commit each issue seperately because the other developers can know why the commit is made and if in future any similar issue occurs, they can refer to the old commits. It is also necessary because your laptop may crash the next day after all your fixes are done and code is in local.
Create multiple branches and don't push your code directly to master branch. The reason is once you have committed the code you can raise a pull request, so that other developers review your code and they can also gain idea on the code you committed.
They can help you if they find any issue so that you will not commit the buggy code to the master branch.
Working with others.
Pull requests are preferred way of merging the code. Once you commit the code and make a pull request other collaborators review the code and either approve it or provide the comments that you need to fix. Create a branch for each issue you are working. We have to create a branch for each issue we are working and after completing it we have to place a pull request to the master branch. Then the collaborators review the pull request and they provide the comments and then if it is good they will merge otherwise they provide comments, that we need to check on. Resolving merge conflicts. If two people worked on same files, then there is a possibility of merge conflicts. We have to resolve the merge conflicts manually and commit it.
Most used git commands
git init
This command creates a new git repository and it is usually one of the first command we use while we start a project.
git remote add <> <>
This command will add remote tracking branch.
git add <>
This command is used to add the files to the staging area
git status
To check the status of the files in the local directory whether any changes to commit or the files we staged.
git commit -m "Message"
To commit the changes we added. The message should be a reasonable message. We have to tell why this code is used in the message so that other developers may come to know that this commit is for the following issue.
git pull
To get the latest changes from the git repository
git push
To push the changes to the git repository