

There is an interesting aspect to the above shown command. See below.ĭeleted branch testbranch1 (was 1a0751b). Remember, this will only delete the branch from local repository. You can delete a git branch locally by executing git branch command with -d option. We can now delete our testbranch1 from local as well as remote. Now our master branch should have all the changes from testbranch1. I am not using any pull request and review process here, as this is purely for illustration. Well if you are using something like github or gitlab, directly merging without pull request and review is not permitted. This can be done by first switching to master branch, and then executing the merge command. Let us go ahead and merge our testbranch1 to master. Once you have your changes from testbranch1 merged to master branch, you should be able to delete the testbranch1 from local as well as remote as it is pretty useless if you are not going to work on it afterwards. The push operation will create this new branch with its relevant history in the remote repository as well. * testbranch1 -> testbranch1Īs shown above, we created 3 new test files, and added it and committed them and then later on pushed it. Adding test files d e fģ files changed, 0 insertions(+), 0 deletions(-) $ git commit -a -m "Adding test files d e f" Now let us do some changes and make a commit. The HEAD should now be pointed to testbranch1 rather than master as we saw earlier.Ġ807c9a (HEAD -> testbranch1, origin/master, origin/HEAD, master) Adding test files a b c We can confirm whether we are indeed inside our new branch by running any of the below commands. The command "git checkout -b testbranch1" is a shortcut to create a branch and get inside that new branch - Basically one single command instead of the above two. The command "git checkout testbranch1" will take you inside that branch The command "git branch testbranch1" will create the branch Actually creating a branch and getting inside that branch is two seperate commands. Any work done from this point onwards will be part of this new branch. The above shown command will create a branch named testbranch1, and will take you inside that new branch. This can be achieved by running the below commands. Let us create one branch now inside this repository. And the above command also shows us that there are two commits in this master branch, with their respective commit messages.

The HEAD is pointing to master, meaning we are currently inside master branch. Once we clone the repository, let us get inside the test-repo directory, and see the commits and current branch we are in.Ġ807c9a (HEAD -> master, origin/master, origin/HEAD) Adding test files a b c Remote: Total 6 (delta 0), reused 3 (delta 0), pack-reused 0 Remote: Compressing objects: 100% (3/3), done. It has just one single branch (ie: the default branch master), and 2 commits in that branch. Well this a repository i created for pure illustration purposes. The below will clone an existing repository named "test-repo".

Clone the Repository and create few branches Let us create a repository with few test files, and also create and delete few branches. Once your changes from a branch is merged to the main line of development, it actually is quite useless, unless you are actively using it for further development.īeing said that.Keep in mind that deleting a branch won't improve performance or disk utilization (this is because git branches are nothing but pointers to a specific commit id - the last commit id of the source branch from where you created the new branch) Being said that, it is a common practice among users of git, to delete branches that have been merged to main line development (master branch in most cases.Well it depends on your git repository structure.)ĭeleting a branch is a good idea because… Different people have different opinion about deleting a branch. This article will dig through the delete operation of a branch in git. Unlike other version controlling tools, switching between branches is lightning fast in Git. Although many other version controlling tools offer branching feature, none of them implemented branching in the manner git implemented it (it is extremely light weight). It is distributed in nature, it is decentralized, you can do almost every operation locally (meaning connectivity is only required while pushing the changes).Īnother killer feature git offers is “branches”. There are many reasons for its popularity and adoption. The one single tool that dominates the version controlling space is none other than GiT.
