We are following this model of using git: http://nvie.com/posts/a-successful-git-branching-model/
I'm trying to learn to use git fetch and git merge on the specific merge instead of just pulling. For my question, what I did was made changes to a branch and pushed those changes to the branch. I see those changes on github. Then I switch to master to fetch those changes. So I
git checkout master
git fetch // terminal shows nothing
git fetch origin // terminal shows nothing
Am I using the commands correctly for fetching? I don't see anything on the console. But then when I use a tool like SourceTree, and I fetch, it updates their tree and I can see the changes.
Assuming I get this next step to work, and I see the different changes were made, do I just do a git merge <hash of the last commit or commit I want to merge in>
? Thanks!
git fetch
or git fetch origin
are fine, but if there is nothing to do, nothing is displayed.
You can use git fetch -v
to be more verbose and display more informations
Regarding the last part, as mentioned in "Fun with FETCH_HEAD", you can do:
$ git fetch git://repo.or.cz/stranger.git for-junio
$ git log -p ..FETCH_HEAD
$ git merge FETCH_HEAD
Because "
pull
" is "fetch + merge
", we are explicitly decomposing the operation into two steps."
fetch
" leaves the information on the branch it found on the other side inFETCH_HEAD
, which you can use as to name the commit object sitting at the tip of the branch.
"git log -p ..FETCH_HEAD
" (notice the double dots) lets you view the commits he has but not in your branch with their changes in patch form to inspect what he did was sensible.
If you are satisfied, you can useFETCH_HEAD
to merge the commit in to your branch.
(See for instance this answer)
As detailed in "How Do I 'git fetch
' and 'git merge
' from a Remote Tracking Branch (like 'git pull
')", you don't have to use FETCH_HEAD if you have a upstream branch defined:
git fetch origin
git merge origin/an-other-branch
git fetch origin an-other-branch
stores the fetched tip inFETCH_HEAD
, but notorigin/an-other-branch
(i.e. the usual ‘remote tracking branch’).
So, one could dogit fetch origin an-other-branch && git merge FETCH_HEAD
.
For the first part, make sure your branch has an upstream branch set to your remote upstream repo.
I found this because I was having a similar problem. I don't know the whys, but in my case I needed to explicitly name the branch which was updated:
$ git fetch [origin] [branch]
Let me explain--I use git for small scripts. I start the repo with master
. After the script is deployed in production, and I still want to work on it, I will make a dev
branch. But most projects just have one branch, or I just don't keep dev
once merged.
Today, I updated remote master with a few minor changes, and wanted to update my local system with the changes. Out of habit, I just did $ git fetch
. Nothing happened. Then I found your post. First, I added the project name (origin) and did $ git fetch [origin]
. This updated both dev and master to the last time they shared a merge back in January. Then, OH! I ran $ git fetch [origin] master
, and the changes were now downloaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With