GIT system: Basics, best practices and how to adhere to the GitFlow system
Linus Torvals developed the famous Linux nucleus developer GIT program to become the most used program to save different versions of the code between the developer community, so that it has become indispensable in software projects that require cooperation between work teams, and therefore every developer or programmer must start to identify the basics of the systemHow to use it and best practices and how to adhere to the GitFlow system, which is what we are trying to help through this article.
The basics of GIT system:
The GIT is the most used version system (Version Control System).His idea depends mainly on tracking the series of changes you make on the file.
GIT depends on three work environments:
GIT is usually used as follows:
git initgit add filename git status git diff // Check the differencesgit commit -m "Initial commit" git log
You are now keeping all the adjustments that you made in the code and you can return to it if you need this, but sometimes we are not sure of the code that we have written or from the new Feature feature that we added and we would like to try to add it differently, in this case:
git branch branchName // create new branchgit checkout branchName // Go the new branchgit checkout main // go to the main branchgit merge branchName // merge the code to main git branch -d branchName // delete the branch
Files are stored on the dates of changes on your computer, but you can also use one of the GIT tools with users such as GitHub and Gitbucket sites or Gitlab and it allows you to store a copy of your warehouses and what it contains on the Internet, which allows the ease of sharing it with the work team;Rather, keeping the code in a central place allows everyone to work on the same version of the code simultaneous.
To cooperate with the team through GIT, every individual will often work as follows:
git clone repoLocation cloneNameOfChoicegit fetch git merge origin/branchName// Create a featureBranchName// Repeat fetch and mergegit push branchName origin
The way we have just seen works well, and organized, it allows developers to work simultaneous.But if you are working on a large project, you may want to take your care more than that so that it does not allow the code to merge from the branches to the original code at any time.From here the idea of gitflow work has arisen and it is considered a frame that determines for each developer a specific way to integrate the code so that the original code is always ready for issuance and flaws free.
Learn about the strict workflow of GitFlow
As we talked, the goal of the Gitflow is to ensure the quality and stability of the code.It depends on allocating certain roles for the different Branches, and determines when and how these branches interact with each other.The Gitflow Sir System is based on the presence of two main branches to contribute to them: MAIN main branch is also known as the RELASE BRANC.
In this way, the main branch is ready at any time to release and is largely free of dangerous defects, thus increasing the efficiency of the code and the application becomes more stable;At the same time, developers can work simultaneous.
Well, now we can use GIT and we can apply Gitflow but we can always improve the use of GIT, let's try to review some best practices when using Git.
Best practices when using Git
In this part, we will try to define some useful points when dealing with GIT, but the most important of these points is to write the Commest Messenger clearly as these well -designed messages are the best way to communicate the required context on the changes that have been made to your teammates..So let's initially talk about the best way to write comments:
Here are some other points that will help you use GIT optimally:
// git bisectgit bisect startgit bisect bad head git bisect good dc7a3cfgit bisect reset
All previous points can be applied when you work in a project alone or through a work team;But working with a team calls for a greater commitment to all members of the team in order to maintain high standards for the written code and its efficiency.Here are some important points when you are a member of the team:
Please consider that these practices may differ from person to person or from a team to a team. Therefore, the team must agree on the roads and practices that they will follow during their work on the project and make sure that all the team members adhere to this agreement all the time, to prevent any conflict that may disrupt the team from work.This agreement must also include the method of combining the code using the Git Merge or Git Rebase.
The difference between Git Merge and Git Rebase
There are two main ways to integrate changes from the branch of any other branch, namely Git Merge and Git Rebase.Both matters combine changes, but when using Git Merge the branch to which the MAIN is merged is affected, while the source branch or the Bug remains the date of the comments as it is and therefore some prefer it because it retains the history of changes without prejudice, while Git Rebase is pressingAll changes in the source branch to one change and then integrate it into the other branch, as it re -history of the comments, and some prefer it because it facilitates the review process.
GIT MERGE is easy to use, unparalleled, meaning that it saves all changes and change messages as they are in both integrated branches and you can refer to any of them at a time, and when there are any conflicts in the changes between the two branches, it is resolved only once when merging and does not needTo solve it every time new changes are added to the built -in branch.But it usually results in the history of unorganized changes and makes it worse if it is merged in a periodic way, as it is added to an additional Commit Message when combining any two branches..
And in the case of Git Rebase, it results in the history of organized and clean changes to the branch so that anyone can follow the changes accurately and in the correct order to it and does not add an additional merger message when merging, but rather arranges the messages present in the previous two branches so that they appear as one of the arranged changes.But the idea of rewriting the date of changes and the loss of the original change messages (Commit Messages) to the built.
Use GIT MERGE:
Use the Get Rebase:
If you are not using GIT by please start using it from now, you will thank yourself later;But if you are a user of GIT, please adhere to the best possible practices, you will surely thank your colleagues at work.
This article was written by the second batch in Linschool.
لا يفوتك أيضابرمجةالسابق