How to download changes from a remote repository?
sobes.tech AI
Answer from AI
To download changes from a remote repository, the commands git fetch and git pull are used.
git fetch downloads changes from the remote repository to the local one but does not apply them to the working directory and local branches. This allows you to review changes before integrating them.
git fetch origin // Downloads changes from the remote repository named "origin"
git pull downloads changes from the remote repository and automatically merges them with the current local branch. Essentially, it is a combination of git fetch and git merge.
git pull origin main // Downloads changes from the remote branch main of origin and merges them with the current local branch.
If the current branch tracks a remote branch, you can use the shortened version:
git pull // Downloads and merges changes from the tracked remote branch.
Difference between fetch and pull:
| Command | Action | Effect on working directory and local branches |
|---|---|---|
git fetch |
Downloads changes (branches, commits) from the remote repository | No |
git pull |
Downloads changes and performs a merge with the current branch | Changes the working directory and local branch |
It is recommended to first use git fetch to see changes with git log origin/main or git diff origin/main, and then manually perform a merge with git merge origin/main or git rebase origin/main if greater control over the integration process is needed. git pull is convenient for quick synchronization if you are confident in automatic merging.