The Gitfetchcommand lets you look before you leap.
What Is git fetch, and What Does It Do?
Your local files remain untouched.
fatmawati achmad zaenuri/Shutterstock
Why is that important?
You have to keep your wits about you when you’re working as part of a development team.
Or, to put it another way, thegit pullcommand is like agit fetchfollowed immediately by agit merge.
By default, the first remote repository is called “origin.”
How to Fetch a Single Branch
Fetching information about a single branch is easy.
Addthe name of the branchto the command line to tellfetchyou only need to know about that one branch.
Here, we’re tellingfetchto retrieve the branch “mary-feature” from the remote repository “origin.”
This won’t over-write any existing files if it’s the first time you’ve used this branch.
Note that the local and remote branches have two periods “..” separating them.
The–onelineoption shows thecommitidentifier and the commit message.
The one-line display is useful if a branch contains a great many changes.
To see a little more information, omit the–onelineoption.
We’ll checkout the branch to check that we’re working it is our current, working branch..
The branch is checked out for us, and we’re told that it is behind the remote version.
We can usegit pullto update it, thengit statusto check our status.
We need to tell Git which remote branch we want to merge.
Aneditoropens to allow us to provide a commit message.
We can accept the suggested message, or add our own.
The editor is yourdefault editorunless Git has been configured to use a different editor.
back up your changes when you are ready to proceed.
The merge carries on automatically when the editor is closed.
Our merge was successful because there were no conflicts.
Conflicts arise when the same lines of code are changed by two or more developers.
If that is the case,Git marks up the conflicts in the affected file.
You’ll need to review them in turn and choose which change to keep.
If you actually want what the puppy has shown you, you’ll need topull.
Related:Git rebase: Everything you better Know