Git (DevOps 4)
Hello everyone,
I am Batool Fatima. I am 18 years old. I have been learning DevOps for a month now. This is my fourth code blog. In last blog, I explained the workflow of git. Today, Let's learn about branches, Git conflict and Git Stashing with me.
Branches, Git Conflict and Git Stashing-
Branch-
The above diagram visualizes a repository with two isolated lines of development, One for little features and another for longer running features. By forming branches, Its not only possible to work on both of them in parallel, but it also keeps the main master branch free from error. Git branches are effectively a pointer to snapshot of your changes.
Snapshot- Every time you commit to a git repository, you are saving a snapshot of all the files in your repository. Snapshots basically represents your commit of a particular time. Its gets updated as you change something and commit again.
Some key features of branching-
Any number of branches can be created.
Whenever a new branch is created, then the data of the existing branch is copied to the new branch.
After done with the changes and work one wants to then he/she can merge that branch with main or master branch again.
The <git branch> command lets you create, list, remove or rename branches.
The <git merge> command lets you take the independent lines of development created by <git branch> and integrate them into a single branch.
Git Conflict-
When files having different content but same name from different branches are merged into the master branch the conflict occurs. Also, It also happens when multiple developers try to edit same file and merge it which is same thing as the first one. Conflicts generally arise when two people have changed the same lines in a file, or if one developer deleted a file while another developer was modifying it. In these cases, Git cannot automatically determine what is correct. Conflicts only affect the developer conducting the merge, the rest of the team is unaware of the conflict. Git will mark the file as being conflicted and halt the merging process. It is then the developers' responsibility to resolve the conflict.
Git Stashing-
Suppose you are implementing a new feature for your product and your code is in progress and suddenly you have to some other work on some other project. Now you don't want to commit your half-done code and can't even throw it away. So you need some temporary storage to store it. This is where git stashing comes in light. Stashing takes your unfinished work and saves it on a stack of unfinished changes that you can reapply at any time even in different branch too. We can do <git stash> to stash a modified file. We cannot stash only modified files and not new ones.
Thank You!
Subscribe to my newsletter
Read articles from Batool Fatima directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Batool Fatima
Batool Fatima
Aspiring DevOps engineer with foundational skills in Kubernetes, Jenkins, Maven, Nagios, Docker, Ansible, Chef, Git, and Linux, eager to contribute to automation and efficient system management. On my way to learn terraform and python