Had a peculiar request on one of my posts asking for a tutorial on how to pull
from git. To be honest, I’m not entirely sure if the comment was just trolling
or what, but figured may as well do a post on it.
Cloning a repository
If you want to pull a new copy of a remote repository, you will need to clone
it. Cloning will create a new directory based on the name of the repository,
creates a remote named origin pointed to the URL and the files from the default
branch will be copied locally.
git clone https://github.com/joshtronic/test.git
Fetching a repository
Fetching allows you to pull down all of the changes from other people. Even
though the changes are pulled down, they aren’t actually merged in with your
local copy. To do that, you would need to merge the changes in manually.
This is great for when you are working on your own fork but want to pull down
changes from upstream without necessarily merging them in immediately.
git fetch upstream
and to merge any changes in
git merge upstream/master
Keep in mind that this assumes you have a remote named upstream configured. To
do so, you would need to run something like:
git remote add upstream https://github.com/joshtronic/test.git
Pulling a repository
Pulling is the equivalent of running a fetch and a merge (the aforementioned two
git pull upstream master
That’s it, not a whole lot to it!