Skip to content

Instantly share code, notes, and snippets.

@elfrank
Last active May 7, 2024 00:29
Show Gist options
  • Save elfrank/c08256de9c15e41e1781 to your computer and use it in GitHub Desktop.
Save elfrank/c08256de9c15e41e1781 to your computer and use it in GitHub Desktop.
How to work on someone else's branch

#How to work on someone else's branch

Let's assume you need to collaborate with Batman on his forked repository.

  • First, you need to add his fork as a remote.
git remote add batman git@github.com:batman/iambatman.git
  • Now, you can fetch, pull and push to his fork (if you have permissions to do so).
git fetch batman
  • So, to add changes to the savegotham branch, you must:
# batman is the name of the remote
git checkout -b local-branch-name batman/savegotham
# ...Make changes to local files...
git add -A
git commit -m "The joker is dead"
# batman -> name of remote, savegotham -> name of branch
git push batman savegotham

####Notes:

  • See your remotes with git remote -v
@ashwinvidiyala
Copy link

This was super helpful. Thanks :)

@Johnblaze1
Copy link

Nice

@AnushaPatnala-zz
Copy link

Very helpful. Thanks :)

@xiaoyeliu
Copy link

thanks

@pairofAces
Copy link

Thank you!

@mmpedicone
Copy link

Simple and exactly what I needed, thanks!

@colin-home
Copy link

Once you've pushed your changes, and you don't want to have the remote in your list of remotes anymore, you can remove it:

git remote remove batman

To list your current remotes and verify that the remote you removed is gone, use:

git remote -v

@DittoJoe
Copy link

So simple! Thank you

@michalvalasek
Copy link

Thank you!

@smccarthy-ie
Copy link

Excellent, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment