Bootstrap FreeKB - Git (Version Control) - Download files using the git checkout command
Git (Version Control) - Download files using the git checkout command

Updated:   |  Git (Version Control) articles

There are a number of different ways to download one or more files from Git or GitHub.

The git checkout command can be used to:

Before you can checkout, pull or fetch files, you'll need to use the git clone command to clone an origin Git repository to a directory on your local PC. The most basic way to use Git is to use the git clone command to clone an origin Git repository (such as example.git) to a directory on your PC (such as /home/john.doe/git), make a change to a file in the cloned repository on your PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.

The git checkoutgit pull and git fetch commands can be used to download files in a repository to the currently selected branch of the cloned repository.

AVOID TROUBLE

If your branch already contains a file that is also in the repository, and there are differences between the files, git pull will attempt to integrate and merge the differences into the files in your branch.

git fetch will download but not merge or integrate any differences between similar files

 

In this example, foo.txt will be downloaded from the master branch of the origin Git repository to the currently selected branch of the cloned repository. If no output is returned, this means the commit of the file in the currently selected branch of the cloned repository is exactly the same as the file in the master branch of the origin Git repository.

git checkout master 'path/to/foo.txt'

 

If the following is returned, this suggests that the file does not exist in the master branch of the origin Git repository.

~]$ git checkout master 'path/to/foo.txt'
error: pathspec 'path/to/foo.txt' did not match any file(s) known to git.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 723655 in the box below so that we can be sure you are a human.