Two oddly confusing Git commands for beginners – git fetch
and git pull
used on a daily basis. I’ll try to describe them broadly and get to know how and when to use both of them.
Prerequisites
- Git
Solution
git fetch
pulls any Git metadata information only from a remote origin (GitHub, GitLab, etc. repos). The metadata can include any new commits to existing branches or new branches being pushed by other Git users.
Simply put, it lets you know about any changes made in the remote repo since your last pushed commit by downloading changes on your local machine without merging anything. From my personal experience not a bad idea to add the --prune
parameter too. It will remove any deleted remote origin branches. If working with multiple people, I would suggest running git fetch --prune
once in a while.
git pull
is basically git fetch
+ git merge
. Fetches any remote repository updates to your local machine and automatically merges commits made by others to your local machine code if any. Just be aware of Git merge conflicts.
git pull
is mandatory before pushing any local commits to remote. So, do the following:
git fetch --prune
git pull
Conclusion
To find more neat Git commands and hacks, browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.