Merge local master branch with remote master branch in Git -


i'm in strange situation: have copied directory (local repository) former developer on machine. there have been several commits remote master not in local repository.

how merge local copy of master up-to-date changes of remote master?

case 1: remote/master has local master has

if remote/master contains of commits local master contains, git pull:

git checkout master git pull remote master 

you can check if local master has commits remote/master doesn't using following:

git fetch remote git log --oneline --graph remote/master..master 

that show commits contained in master not in remote/master. if don't see output, means remote/master has local master has.

case 2: local master has commits remote/master doesn't have

if local master contains commits remote/master doesn't contain, you'll have figure out how want handle that. want keep them , merge them remote/master, or want throw them away?

case 2a: merge/rebase local master commits remote/master

if want keep them, can either merge or rebase local master remote/master:

git checkout master git fetch <remote>  # merge remote/master git merge remote/master  # or rebase local commits on top instead git rebase remote/master  # push results git push remote master 

case 2b: throw away local master commits

if don't want keep local commits, hard reset of local master same point remote/master:

git checkout master git fetch remote git reset --hard remote/master 

documentation

you can read more of these commands git documentation. highly recommend excellent free online pro git book, chapters 1-3 , 6-6.5.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -