Git shortcut to pull with clone if no local there yet?
git, jenkins
Solution
`git pull` knows from where to pull from because the local repo has a remote registered in its local config. It operates from a working tree.
But `git clone` doesn't, it must have an explicit remote URL passed in parameter in order to clone. It operates outside the working tree.
The main reason for such a shortcut to not exist is that:
- you `git clone` rarely for a given repo: it is a one-time command in the life of the repo. Plus, it might need an additional command to be complete: if you have submodules, for instance, you would need to add a `git submodule update --init`.
- you `git pull` often within a given repo. `git pull` is in itself a shortcut (for `git fetch` + `git merge`). Even `git pull --rebase` is another shortcut for `git fetch` + `git rebase`.
Considering the number of times you are to use `git clone`, such a shortcut is not a high priority.
So a script remains the surest way to define what you need.
Problem
Is there a one-command way to get an up-to-date mirror of a remote repo? That is - if local repo not there yet: clone - if it's there: pull I know I could script this around (e.g `if [ -d repo ]; then (cd repo && git pull); else git clone $repourl;fi `) , but I need the simplest possible cross-platform way (actually used for Jenkins-CI, which I know does this by default, however I need 2 repos for which support is limited). Git has similar shortcuts for other things (eg. checkout -b, and pull itself), so I'm wondering if I missed something. Thanks!