At what point should I commit to git? [closed]

2

I'm just starting with git and although I know very well his theory commands and others I have a hard time getting used to the practice ...

Let's say that I'm in a project and I'm developing the navigation bar .. should I commit when I have the bar completely ready or in each step of the construction of the navigation bar?

make commits of type: Navigation bar added

or of the type: - Bar Styles list             - Established bar links etc etc. Thanks for your answers!

    
asked by Cristofer Fuentes 13.02.2016 в 02:17
source

2 answers

4

Generally, and not specifically in Git, it is always advisable to make repeated commits to have your versioned changes available in the source control.

Specifically in Git and answering the specific question you have asked:

Assuming the following:

  • You have an assigned task whose specification is to create a navigation bar
  • You're working on a topic branch (also called feature branch)
  • My recommendation is this:

    • If you feel comfortable and confident that you can deliver the corresponding changes to the entire specification without problems since the task is not very complex, then a single commit will suffice.
    • If the task is too complex, I would recommend proposing to divide the task into several subtasks so that you can associate each particular step of the construction of for example the navigation bar with a specific commit.
    • If the task is simple however you consider that it is better for you to perform several commits for whatever reason, for example because you want to understand the changes better or it seems more orderly, then do it that way, there is no problem. If in any case there was a policy of a checkin per task or if you later regret it and consider that you have done many checkins for something very simple you always have the possibility of joining them in one before doing push through what is known as < a href="http://git-scm.com/docs/git-rebase#_interactive_mode"> squash

    In the end the most important thing to remember is what @Kristian Damian mentions in his answer: Basically, each checkin must contain changes that are functionally complete without breaking the code, unit test or build process that you have established.

    The rest can be very subjective and depends on each case and each person

        
    answered by 13.02.2016 / 05:47
    source
    1

    As Alvaro says, it's more a matter of styles, but in the best git practices you are invited to commit temprano y seguido

    One of the advantages that you would get by committing is the possibility of returning to several previous states in case of a bug difficult to track, but it is important to take into account that you should establish minimum rules for the commit, such as:

    • That the code is not broken (or compile depending on the language)
    • That the current state does not break the unit tests
    • Do not interfere with another partner's code

    Basically it's about being a good citizen with the rest of the team members or facilitating the cloning of your branch

        
    answered by 13.02.2016 в 02:51