user3754971
user3754971

Reputation: 79

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 ?

Upvotes: 2

Views: 3784

Answers (2)

Jack O'Connor
Jack O'Connor

Reputation: 10886

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.

Upvotes: 0

user456814
user456814

Reputation:

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

Upvotes: 8

Related Questions