Search code examples
gitcommand-line-interfaceatlassian-sourcetreerebasegit-flow

SourceTree finish feature with rebase - CLI equivalent


I've been using for some time SourceTree to perform all GitFlow operations, including closing feature branches.

Now I would like to better understand how to perform some operations via the git CLI.

In particular, I haven't understood what would be the CLI equivalent of closing a feature by also selecting the rebase option, as in the image below.

enter image description here

I have tried merging, but that does not reproduce the whole process, what would be CLI command to perform the same operation as those executed by SourceTree?


Solution

  • The original command line suggestions, which most GitFlow tooling is derived from can be found on the original blog post article here:

    https://nvie.com/posts/a-successful-git-branching-model/#incorporating-a-finished-feature-on-develop

    Closing a feature branch consists of the following steps:

    $ git checkout develop
    Switched to branch 'develop'
    $ git merge --no-ff myfeature
    Updating ea1b82a..05e9557
    (Summary of changes)
    $ git branch -d myfeature
    Deleted branch myfeature (was 05e9557).
    $ git push origin develop
    

    The checkbox option in SourceTree likely does one additional step which is rebasing the current feature branch onto the head of the develop branch before merging. If you are not familiar with the git rebase operation, I would suggest that you read about it here first:

    https://git-scm.com/docs/git-rebase

    NOTE: While a rebase operation is a perfectly normal workflow to follow, I use it almost daily, it can cause problems if you are just using it for the first time, especially if there are conflicts between the feature branch you are working on and what is on the develop branch. I would encourage you to try the following in isolation to get used to what is happening.

    So, looking at the "normal" finishing of a feature workflow from above, you would do something like the following:

    $ git checkout myfeature
    Switched to branch 'myfeature'
    $ git rebase develop
    Replay commits from myfeature branch onto the head of the current develop branch
    $ git checkout develop
    Switched to branch 'develop'
    $ git merge --no-ff myfeature
    Updating ea1b82a..05e9557
    (Summary of changes)
    $ git branch -d myfeature
    Deleted branch myfeature (was 05e9557).
    $ git push origin develop
    

    If you look at the history of your git repository before and after the rebase operation, you should hopefully get a feel for what is happening. If you are still unsure, you might want to use something like the following:

    http://git-school.github.io/visualizing-git

    Which will help you to visualize the git operations that are taking place.