Search code examples
gitgit-fetch

How to git fetch from a central remote repository?


I'm new to Git and I'm a little confused how to use "git fetch"

I have a central repository that I access using SSH, I have created a repository using git clone, just like this:

$ cd /my/local/repotest
$ git clone ssh://[email protected]/var/github/repotest .

Now other developer have pushed some new files to the central repo in "somedomain.com"

My question is, how can I fetch the new files and changes via command line?


Solution

  • To use a another repository you need to define some "remotes". You add them to your .git/config file like so:

    [remote "origin"]
    url = ssh://server.hostname.com/home/me/git/myrepo
    fetch = +refs/heads/*:refs/remotes/origin/*
    

    Once your cloned repo has these, you can push or pull changes like so:

    git pull origin 
    git push origin
    

    See also git help remote and git help pull. I also find github's help pages quite helpful.