This post will briefly explain about updating the Git local changes with the remote server with the help of the “get fetch” command.
How to Update Git Local Repository With Remote Server Using “git fetch” Command?
To update the Git local repository with the remote server using the “git fetch” command, follow the below step-by-step procedure:
- Navigate to the Git root directory.
- List all local and remote branches.
- Execute the “git remote add” to add the remote along with the desired repository URL.
- Check the remote using the “git remote -v” command.
- Next, fetch all local changes.
- Show remote fetched branches by running the “git remote show main” command.
- Lastly, push all the local changes to update with the remote server.
Step 1: Move to Git Local Repository
Initially, navigate to the Git repository according to your preference with the help of the “cd” command:
Step 2: List all Remote and Local Branch
Execute the “git branch -a” to list all the remote and local branches:
As a result, all the available local and remote branches have been listed successfully:
Step 3: Add Git Remote
Utilize the “git remote add” command along with the remote branch name, remote name and add the desired remote repository path to it:
Step 4: Check Remote
Next, check whether the remote is added or not in the current working repository by executing the “git remote -v” branch:
It can be noticed that the remote has been added successfully:
Step 5: Fetch Local Changes
Now, fetch all the local changes by applying the “git fetch” command along with the branch name:
As you can see, the changes have been fetched in the main branch successfully:
Step 6: Show Remote Fetched Branches
Run the “git remote show main” command to display all remote fetches branches:
The provided output represents all the remote-fetched branches:
Step 7: Push Local Changes
Lastly, execute the “git push” command to push all the local changes to the remote repository:
The below-stated output indicates that everything has been up to date:
We have provided the easiest solution for updating the Git local repository with the remote server using the “git fetch” command.
Conclusion
To update the Git local repository with the remote server, the “git fetch” command can be used. To do so, first, navigate to the Git root directory, list all local and remote branches. Next, execute the “git remote add” to add the remote URL. Then, fetch all local changes and show remote-fetched branches by running the “git remote show main” command. Lastly, push all the local changes to update with the remote server. This post provided the solution for updating the Git local repository with the remote server using the “git fetch” command.