0

We have two Git branches, dev and master. Both are in stash. When starting, I was on the local copy of the master branch. I ran Git checkout dev to switch to the dev branch then wanted to check what updates will flow in if I do a Git pull so I ran:

git fetch

but despite me being on the dev branch, fetch downloaded objects and refs for both dev and master! I expected it would do so for only the current branch:

tom@saltmstr:/opt/salt $ git fetch
remote: Counting objects: 67, done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 67 (delta 44), reused 15 (delta 7)
Unpacking objects: 100% (67/67), done.
From git+ssh://stash.mds.xyz:7999/mds/salt
   3ec937f..f53d944  dev        -> origin/dev
   f4b87bb..3d17dd5  master     -> origin/master
tom@saltmstr:/opt/salt $ git fetch

What would be the correct syntax for Git fetch and Git pull to bring in changes only to the dev branch?

git fetch -b dev ?
git pull -b dev ?

or would it be:

git fetch -b dev origin/dev?
git pull -b dev origin/dev?

I couldn't find anything about ONLY checking out a specific branch using either fetch or pull so I'm posting the question.

Kara
  • 6,115
  • 16
  • 50
  • 57
xBlender
  • 21
  • 6
  • This action is just synchronizing the remote repository with your local repository. – rasmeister Mar 08 '17 at 16:12
  • I only need to synchronize the local dev with the remote dev. How to do this? I don't want to sync master at this time. – xBlender Mar 08 '17 at 17:14
  • 1
    You can do `git pull origin dev` assuming your remote is referenced as `origin` and your branch is `dev`. – rasmeister Mar 08 '17 at 17:21
  • Kool, ty. Likewise if I do a `git fetch origin dev` will it only affect the dev branch unlike my earlier attempt that fetched for both dev and master? – xBlender Mar 08 '17 at 17:48
  • Should behave the same way – rasmeister Mar 08 '17 at 17:52
  • Might want to have a look at [this as well](http://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch?rq=1) – rasmeister Mar 08 '17 at 17:56
  • `git fetch origin dev` didn't work. I can clearly see the branches when I type `git branch -a` however: ` # git branch -a|grep -Ei "master|dev" * dev master origin/dev remotes/origin/dev remotes/origin/master` – xBlender Mar 08 '17 at 18:54
  • Sorry just saw your second comment. I did go through that link but haven't seen the specific reference to what I wanted. I'm going through it again. I basically get: `"The requested repository does not exist, or you do not have permission to access it."` – xBlender Mar 08 '17 at 18:59
  • I don't understand. If `git pull origin dev` works, then `git fetch origin dev` must work also. The only difference is it doesn't merge with your working changes in the latter case (fetch). – rasmeister Mar 08 '17 at 20:18
  • Neither do I. What is the command syntax you use for both? Let me follow your working one and see. – xBlender Mar 08 '17 at 20:23
  • If you go to [this link](http://ndpsoftware.com/git-cheatsheet.html#loc=local_repo;) and click on the 'Upstream Repository' you will see that git pull and git fetch largely have the same syntax. The commands I listed in my earlier comment are the ones I use (except I have `develop` instead of `dev` as my develop branch). – rasmeister Mar 08 '17 at 20:27
  • Thanks guy's. I was able to get things going with these tips. – xBlender Mar 29 '17 at 04:20

1 Answers1

0

You have to use a refspec to let Git know which remote ref maps to which local ref:

git fetch origin dev:origin/dev
knittl
  • 246,190
  • 53
  • 318
  • 364