0

Is there a simple command in windows powershell to get the latest code from a git remote repository? I have already installed git posh

Note:

  1. New to both git and powershell.
  2. I am not creating a repository. I just want to get the code from a remote branch so that I want to build using ms build tool in the next step of the powershell script.
VivekDev
  • 20,868
  • 27
  • 132
  • 202

1 Answers1

0

You can use git clone

git clone <http or ssh address for the repository>

If you have already cloned the repo, you need to checkout the branch then pull it.

git checkout <branch name>
git pull

If you have no branches available to checkout from remote:

git fetch origin

And see what branches are available to checkout with:

git checkout -v -a
enjoi
  • 274
  • 4
  • 15
  • I am sorry if I am not clear by the question, but I dont want to clone the repository. I just want to get the latest code so that I can build it. This is build machine, not development machine. – VivekDev Oct 01 '16 at 12:15
  • 1
    Do you already have a local working copy and just want to update it? – enjoi Oct 01 '16 at 12:17
  • No, I dont have a local working copy. i dont want to create a git repository. i just want the code from the remote so that I can create a build and publish it. – VivekDev Oct 01 '16 at 12:21
  • 1
    Github allows you to just download a zip files of all the code if you want to do that. However, it would be much easier to git clone. – enjoi Oct 01 '16 at 12:22
  • Your last comment nudged me to the right direction. I have to somehow get the zip of the HEAD of the concerned branch. Thanks again for the pointer. – VivekDev Oct 01 '16 at 12:29
  • I should have looked at [this](http://stackoverflow.com/questions/17682143/download-private-bitbucket-repository-zip-file-using-http-authentication) and [this](http://stackoverflow.com/questions/13044749/bitbucket-download-source-as-zip) so questions – VivekDev Oct 01 '16 at 12:54
  • Yeah curl would work nicely for that sort of thing if you wanted to use powershell. Downloading the ZIP file through the browser is all good too! I personally find curl a bit annoying at time when copying and pasting the comments because it doesn't always persist the quotation marks and things like that and throws errors. – enjoi Oct 01 '16 at 13:32
  • You could clone just the current data: `git clone --depth 1 --branch main https://cloneurl`, you end up with a git repo that only has the data for the latest version if the selected branch. – jessehouwing Dec 24 '20 at 20:38