AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Git fetch and rebase11/8/2023 And now, the changes which were made in the feature branch will exist on the master branch as well.įig 5: Merging of feature branch with the master branch Once you are done with the changes, we simply ‘merge’ the changes of the ‘feature’ branch to the ‘master branch’. Now, any new changes that you will do on the feature branch, will not affect the code on the master branch.įig 4: Master branch and the Feature branch So, we create a new branch from the master branch, let’s call it a ‘feature branch. Now, we don’t want to touch the master branch code, we want to copy the code of the master branch to a new place, where we can experiment or change the code. So, the website we showed you above is the master branch. ![]() By default, all your code is stored on a master branch. So, in git to isolate different versions of code we have branches. Make changes in the code, and then once the changes are finalised, you will replace the code in the main folder right? Let us understand how we can do the above thing in git. So, what do you do? Ideally, you will copy the code of this website in a new folder. But if you are changing the code, you do not want the changes to be reflected in the main website which is deployed. For this, you will have to change the code of the website. You want to add more features to this website. The website looks something like this.įig 3: Sample example of the website before changes Let us take an example to understand this, Let’s say you have a website that is currently running. So whenever we make any change, it generates a new commit.įig 2: The changes made in the repository will be saved as a new commit with a new commit id What is a Branch?Ī Branch is a representation of different isolated versions of code. These changes in git will be saved as another commit with another commit-id 14343. Now let us say we have made some changes to the code by adding another python file. Each commit has a commit-id, let it be 1234 in our case. These four python files will be saved inside a commit. In Fig: 1, Let us assume that we have four python files. ![]() Let us take an example and discuss in brief from the diagram shown below:įig 1: The changes made are saved in a commit What is a Commit?Ĭommit is defined as the location where the code and its changes are stored. Let’s understand these two terms respectively. How can Git Rebase and Git Merge be used together?įor understanding the working of git, we need to understand the two fundamental concepts in git which is git commit and git branch.If you want to know the details or have an old git version, follow the literature pointers above.So, the following are the topics covered in this blog: If you want to combine local commits before pushing them upstream, for example, because you discovered a typo or bug after a commit, you can do this interactively: To avoid typing -rebase whenever you pull you can config git to use it as default: Published commits are, however, usually merged, for example when branches are merged. As nobody knows your commits yet, nobody will be confused when they are rebased but the additional commit of a merge would be unnecessarily confusing. It is best practice to always rebase your local commits when you pull before pushing them. This results in a merge commit that points to the latest local commit and the latest remote commit. If you pull remote changes with the flag -merge, which is also the default, then your local changes are merged with the remote changes. ![]() If you pull remote changes with the flag -rebase, then your local changes are reapplied on top of the remote changes. If you want to understand the details of rebasing and merging for changes and branches, then syou should read a blogpost by Mislav Marohnić and the chapter on rebasing and merging from the Pro Git book. There is another wikipage on how to rebase or merge a branch. This page briefly explains the difference between rebasing and merging in git while pulling.īoth techniques are used to combine your local unpublished changes with the published remote changes.
0 Comments
Read More
Leave a Reply. |