Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone vs git pull

For my project I keep an online repository on github and local repositories on two computers (say A, B) where I write code and run tests and also on three other machines (say, C, D, E) where I just run tests.

Now, it happened a few times that there are conflicts whenever I want to just download updated code on C, D, E and doing just git pull origin $someBranch won't work, probably due to some small modifications that I did on the local source code just for testing purposes and which I don't want to keep.

What should I do in this case? Should I always do git clone $URLofMyRepository or are there less aggressive ways?

like image 497
Ricky Robinson Avatar asked Jan 30 '13 09:01

Ricky Robinson


People also ask

What is the difference between git clone and git pull?

git pull is a (clone(download) + merge) operation and mostly used when you are working as teamwork. In other words, when you want the recent changes in that project, you can pull. The clone will setup additional remote-tracking branches.

Do I need to do git pull after git clone?

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).

What is git clone?

git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.

What is git pull used for?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.


1 Answers

You can remove the changes to your branch if you do not want to keep them using:

git checkout .

This should remove all unsaved changes to your working directory, allowing you to perform a pull.

git pull origin $someBranch

If you want to keep the changes in your branch try stashing them, then running the pull command.

git stash

Assuming no other stashes have occurred these changes can be applied at a later time by performing:

git stash apply
like image 122
Kevin Bowersox Avatar answered Sep 21 '22 03:09

Kevin Bowersox