0

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://andre@somedomain.com/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?

Mat
  • 202,337
  • 40
  • 393
  • 406
André
  • 24,706
  • 43
  • 121
  • 178
  • http://gitref.org/remotes/#fetch You should read gitref.org. All basic commands n usage is given there nicely... – Girish Oct 06 '11 at 17:15

3 Answers3

1

Use git fetch or git pull from within your local tree.

git pull is shorthand for performing a 'git fetch' followed by a 'git merge'. For more information on the difference between fetch and pull, check out the following: What's the difference between git pull and git fetch?

Community
  • 1
  • 1
Brandon E Taylor
  • 24,881
  • 6
  • 47
  • 71
1

You probably want to use git pull or git pull --rebase in this case. git pull does a git fetch from the repo and "updates" ( merge in the first form, rebase in the --rebase form) your working directory as well.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Thanks for your reply. It is possible also to pull only the new files? I'm using git to pull the files from a central repository to a production environment, but I don't want to change the files in my local repo. This is possible? – André Oct 06 '11 at 17:16
1

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.

IanNorton
  • 7,145
  • 2
  • 25
  • 28