Is there a one-command way to get an up-to-date mirror of a remote repo? That is
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!
In review, git fetch is a primary command used to download contents from a remote repository. git fetch is used in conjunction with git remote , git branch , git checkout , and git reset to update a local repository to the state of a remote.
Git Fetch is the command that tells the local repository that there are changes available in the remote repository without bringing the changes into the local repository. Git Pull on the other hand brings the copy of the remote directory changes into the local repository.
There is not, given that the commands which operate on existing repos all assume that they're being run inside a given repo.
That said, if you're running in a shell, you could simply make use of the shell built-ins. For instance, here's bash:
if cd repo; then git pull; else git clone https://server/repo repo; fi
This checks to see if repo
is a valid directory, and if so, does a pull
within it; otherwise it does a clone
to create the directory.
The cleanest one-liner might be
git -C repo pull || git clone https://server/repo repo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With