This is one that can be a little confusing for some. I know it was for me for quite some time too and part of that is because of the name and some times the message that gets thrown on the terminal window when you run git status
. That was the case for me because that was the command I always ran when I tried to bring my local code up to date. The thing about that is knowing when to use which command. It may not be super intuitive for all – I know it wasn’t for me.
The message I’m talking about is:
❯ git status
On branch master
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
That is a slightly simplified version of the message. There are times when it may show that your local is ahead by one or more commits. Yes, that has happened to me a few times and the result hurt after because to be honest I wasn’t completely sure what it was that I was doing. I just didn’t. Again that was in part because I didn’t know what the command was really doing internally.
Again, much like the previous posts let’s take a quick look at the documentation on the command which can be found here. The part that I really want to highlight is this section of the description:
More precisely,
git pull
runsgit fetch
with the given parameters and then depending on configuration options or command line flags, will call eithergit rebase
orgit merge
to reconcile diverging branches.
I want to emphasize two things here. The first is thefetch
command and the second being the two last commands mentioned. We can see it does either a rebase
or a merge
. This is where things might get a little hairy if you don’t know what you are doing; and I say this because there was a time even I didn’t know what I was really doing. Both of those will add an additional commit to your local working copy of the repository. This is an important thing to note if you have made any changes to any of the files that are being version controlled.
It can lead to a slight headache if you end up doing that too. I’ve done that once or four times too. The super neat part is that git does also give you a heads up when there are changes on the current working branch. This is one of those things to note as well.
You can pull in changes to the other branches that are on your local copy. Something like the following snippet of code:
git pull origin feature-27
Super great if you are working with other people on development of features or even bug fixes. Just pull those changes in with git pull
and continue work on your branch or if you are just looking to get all the latest changes and commits to your local copy.