Git Fetch
Definition
git fetch is a command that downloads commits, files, and references from a remote repository into your local repository. It updates your remote-tracking branches without modifying your current working files or merging changes.
Where you hear it
- During team code reviews. - When preparing to update your local branch with the latest changes from the server. - In tutorials explaining the difference between fetching and pulling.
Examples
Run
git fetch originto see if there are any new updates on the server.I need to run
git fetchbefore I can see the new branch my teammate pushed.Run git fetch to see the branch your teammate pushed, without changing your own work.
Common mistake
Many beginners think git fetch automatically updates their current working files. It only updates the local metadata, so you must perform a git merge or git pull if you want to apply those changes to your code.
Don't confuse with
Git fetch vs. git pull: fetch only downloads the latest data from the remote repository without changing your local files, whereas pull performs both a fetch and an immediate merge into your current branch.
Say it at work
- In a meeting or chat
I'll run a quick git fetch to make sure my local tracking branches are up to date with the remote.
- In an email or ticket
Please run git fetch to retrieve the latest commits before you start working on the integration branch.
Keep exploring
More in Git & Collaboration