简体   繁体   中英

How can I synchronize github with a local repository?

I didn't find a clear answer to this one (many things are overwhelming to newbies at git):

I have a local repo and a remote at github consisting of files: A, B and C.

  • This morning I changed local file A.
  • At noon, remote B was changed.
  • Later on, I decided to change some comments at local file C and some code at remote C.

My draw depicts the files and their changes:

local       remote
 A  ------->   A
 B  <-------   B
 C  <------>   C    

In the evening, I'm just staring the repos. Is there any chance to finish promptly? Anyone?

Commit all of your local changes first. Make sure your working directory is clean:

$ git status

should return: nothing to commit, working directory clean

Then, pull in the remote's changes:

$ git pull remote-name branch-name
# it's probably git pull origin master

Then push your changes to share with the remote:

$ git push origin master

My local workfolw allows your to untie the pull and push stages properly, and it is the following:

  1. Store your local uncommitted changes with git stash :

     git stash 
  2. Update your local repo with remote version one:

     git pull 

    So you get:

     local remote B <------- B C <------- C 
  3. Apply local changes, and merge all inconsistiences, fix the files if any require, and add them into index, and commit merge:

     git stash pop vim ... git add . git commit 
  4. Edit file C , and commit it.

     vim C git add C git commit 
  5. Push changes into remove repo:

     git push 

    So you'll get:

     local remote A -------> B C -------> C 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM