简体   繁体   中英

syncing two local repos via github when a .gitignore is involved

I'm trying to determine the best method/command flow to get two local projects synced. Say I have original source code from an example sample online at 2 locations, home and work and i'm using github as my remote repository. let's also say not all the files in the project need to be pushed to github, so I'm using a .gitignore to exclude those files from being added, committed or pushed.

So I'm at work and make some changes to a file, add, commit and push to github.

What should I be doing at home to get those changes updated there? Should I be doing an initial commit at home of the original files, then doing a pull or fetch? Do I need to have that .gitignore at home before doing an initial commit so all the appropriate files are ignored? If so, should I be pulling the .gitignore from github to home before committing the original, followed by pulling the changed files from github?

I think the .gitignore is throwing me off.

All of this can happen on the master branch.

I've tried a couple different methods, but nothing has seemed to work for me.

If you have already cloned the github repository at home, all you need to do to get your working copy up-to-date is a git pull.

If you added your .gitignore file at work as well (and committed and pushed it), it will be pulled with the rest of the modifications, and then your working copy at home will ignore the same files, simple as that.

Fetch doesn't actually apply any changes on your working copy, it will just download them from the remote to your local repository, and you could merge the retrieved branch heads into the current branch - this is essentially what git pull does in it's default mode.

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