Git (Version Control) - Download files from origin repository using the git checkout command

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 an origin repository to the currently selected branch of the cloned repository.

AVOID TROUBLE

If your branch already contains a file that is also in the origin Git 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 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 origin Git repository.

git checkout 'path/to/foo.txt'

 

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

~]$ git checkout '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

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |