With git pull -ff-only, Git will update your branch only if it can be “fast-forwarded” without creating new commits. Instead, Git will happily merge origin/master into your branch! How Git Pull –ff-only Worksįortunately, Git gives us an option that prevents the accidental creation of new shas in your repository. If you have my-branch checked out, and you run git pull origin master, this does not simply update your local master. If you run git pull or git pull origin master, you end up with this:Īnother problem is when you are on a different branch. You have committed work on your local branch, and someone else made a new commit that is only on remote. Therefore, by default, pulling from the remote is not a harmless operation: it can creates a new commit sha that didn’t exist before! I find that this behavior confuses Git novices, because what feels like it should be a harmless download operation actually changes the commit history in unpredictable ways.Ĭonsider the following situation. There’s the problem: git pull performs a merge, which often creates a merge commit. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD. However, what the command actually does is explained in the next sentence. Incorporates changes from a remote repository into the current branch. The description of git pull in git pull -help looks rather harmless. If you get nothing else out of this blog post, it should be that running the following simple command will save you many headaches as a novice Git user. In this blog post, I will advocate for using the -ff-only option for git pull, and furthermore setting it as the default option for git pull. Often, there is one root cause: Git trying to be helpful and performing operations on your repository that you did not intend. Having introduced Git to many dozens of people, first as a teaching assistant and now as a professional software engineer, I have seen many of the mistakes that Git novices commonly make. Like many great things, if you are new to Git, it takes trial and error before you can come to appreciate its power and simplicity. Git is a simple, elegant version control system.
0 Comments
Leave a Reply. |