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

Updated:   |  Git (Version Control) articles

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

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 git checkoutgit pull and git fetch commands can be used to download files in a repository to the currently selected branch of a cloned repository

The most basic way to use Git is to use the git clone command to clone a 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.

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

 

The git branch command with the -a or --all flag can be used to display all of the branches in the repository. The wildcard character is used to identify the branch you are currently using (master in this example).

~]# git branch --all
  development
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feat/logging
  remotes/origin/master

 

The git pull command without any options will pull files from the origin to your currently selected branch.

git fetch

 

Or you can include origin and the name of your currently selected branch (master in this example).

git fetch origin master

 

The prior command will return "Already up-to-date" if your the files in your currently selected branch are the same revision as the files in the origin Git repository.

Already up-to-date.

 

The -q or --quiet option can be used to suppress output.

git fetch --quiet

 




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 48fbb6 in the box below so that we can be sure you are a human.