简体   繁体   中英

Taking a git diff and creating a new branch in different repo

We two friends are working on a project:

I have made some local changes in my project, which still needs to be committed. when i take a git diff it lists out the difference between my local repo and staging area.

My other friend is working on the same project and want to add the git diff in my local repo to his own local repo as a different branch.

What is the way to do this ?

As pointed out in the comments , the typical way to share changes is via pushes and fetches to remote repos, and pull requests.

However , if you really want to use diffs as patches instead, then you can send to your friend the diff/patch as a file (or copy and paste into an email or instant messaging, if you're okay with the security of those channels...or lack thereof). Your friend can then attempt to apply the patch to his own local branch.

What you need to do

git diff > diff.patch

Send diff.patch to your friend.

What your friend needs to do

git apply diff.patch

Documentation

git apply is the command you're looking for. However:

I have made some local changes in my project, which still needs to be committed.

The standard git advice is "commit early, commit often," and it's very good advice. I'd recommend getting comfortable working with commits (reordering them, editing them, squashing them, and pushing them around). Once you've committed changes, git will essentially never lose your work. Commands like git reflog can do magic to get your commits back. But many commands ( reset , checkout ) can pave over your uncommitted work and ruin your day. And of course, you have to have commits to push your changes over the network, as others have suggested.

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