Reputation: 10767
I have seen a few people running:
git clone <url>
git pull
I personally only ran git clone <url>
for all the projects are worked for.
I read in the documentation this:
After the clone, a plain git fetch without arguments will update all the remote-tracking branches, and a git pull without arguments will in addition merge the remote master branch into the current master branch, if any (this is untrue when "--single-branch" is given; see below).
but it didn't really give me a reason for it.
My question is: What is the added value of git pull
when I just cloned the project a second ago? Should I always run a git pull
as well after git clone <url>
?
Thanks
Upvotes: 15
Views: 11098
Reputation: 866
Many times I have run into issues where a git clone did NOT get everything from the server. Even though it is has not been very long, maybe a few minutes, and there is no one else making changes. Creating a new branch, running git clone on the new branch, make a few changes, then a git push errors saying that the local is not up to date with the repository. To this day I have no idea why creating a branch and then cloning that branch does not get everything up to date on the local, but it happens often.
Upvotes: 0
Reputation: 11978
My question is: What is the added value of git pull when I just cloned the project a second ago? Should I always run a git pull as well after git clone ?
It ensures that your code is the most up-to-date prior to you working on it. I get into the habit of running git pull
prior to working on any new development as a sanity check to make sure no other developers pushed any code.
If the clone took a second and you start working on it immediately- its virtually unlikely that there will be any changes you missed. But its still a good habit to make sure you have the latest changes, even if you're reasonable sure you're up-to-date.
Upvotes: 4
Reputation: 59073
The answer is "it depends". How long did it take to clone the repo? Do you think someone has made additional commits since you cloned it? If the answer to that is "yes", then pull.
If the clone took 5 seconds, it's not likely. If it took 30 minutes, maybe.
There's no harm in doing a pull immediately after a clone.
Upvotes: 17