0

Let say I'm on the road with a friend, we are offline from the bare git repository. I have a working copy (with .git folder) and my friend want to help me out so he clone my git repository from my working copy and work on its own and of course both copy are checkout so basically I can not commit and he can not push until one of us make a branch. Is there a better way to do this? is there a way to not have our local master checkout? I guess I can always create a bare git locally and both of us can point to it but that seem a bit over killing. The goal is for him to merge easily his change to mine and then when I'm online I will commit all of that.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
wily
  • 355
  • 1
  • 3
  • 9
  • Possibly related or duplicate: [Git push error '\[remote rejected\] master -> master (branch is currently checked out)'](http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked). –  Jul 31 '13 at 04:44
  • How is it possible that neither of you can commit to your own local clones? Do you mean neither of you can ***push*** changes to each other? Committing and pushing are two very different things in Git. Details matter! Also, what do you mean by your friend "cloning your working copy"? You can't clone a Git repo from a working copy, because they don't contain history, you can only clone from other repos. Please clarify your question. –  Jul 31 '13 at 04:47
  • thanks Cupcake, my friend working copy is made from my git repository working copy. So I can not commit and he can commit but he can not push in my working copy git repository (remote for him) as both are checkout, so we can make it work as specified by creating a branch but this seem a bit overkilling. Is there a way to not have the my local working copy checkout? The otherway we tried which work well but is also a bit overkilling is to create a bare repository on my laptop and he and I create a git clone from there...but that is a bit overkilling. – wily Jul 31 '13 at 05:43
  • The question is still extremely vague, please add ***exact details*** for what has been done and what your friend is trying to do. ***Add the exact commands used***. How did your friend make a cloned repo? Are you and your friend sharing the same computer, or working from two different computers? What commands are you both using? –  Jul 31 '13 at 12:26

3 Answers3

2

There are some details missing from the question, but I'll attempt to answer anyways. First of all, if you both have your own copies of the repo, then you both should be able to commit changes to your own local copies.

If your friend is trying to push his changes to your local repo, it sounds like it's not working because you currently have master checked out, which would make sense as a safety feature...you wouldn't want to have Git silently swap out your working copy from right under your nose without warning. You can allow Git to move your master branch/reference/label/pointer by checking out the commit it's on directly:

$ git checkout head

Then your friend would probably be able to push his changes to your repo. After he's done, be sure to checkout the master branch again in your local repo (if you want to work on it):

$ git checkout master

However, people don't usually push changes to other people's personal/private repos. They usually send each other pull requests instead, and fetch each other's changes. So you could add your friend's remote and fetch his changes and then merge them in (or pull to do both):

$ git add <friend name> <url or path to friend remote>

$ git fetch <friend remote>
$ git merge <friend>/master

# Or combine fetch and merge using pull
$ git pull <friend> master

Alternatively, instead of fetching and merging (or pulling) your friend's changes into your local master branch, you can rebase your local changes on top of his changes:

$ git fetch <friend remote>
$ git rebase <friend>/master master
  • exactly, is there a way to have my local master not checkout? so my friend can push, then I will do an pull and commit....thanks I will try all the solutions you propose to see what is the easiest working solution - thanks again. – wily Jul 31 '13 at 05:48
  • Thanks Cupcake all works well with the 2 solution you propose. – wily Jul 31 '13 at 15:33
  • Thinking more about it I might go with creating a bare repository (Sebastian solution) in case someone else add up....thought I can always add an extra remote friend repository if I want...wow git is really versatile... (still learning, sorry if my questions were not always super clear) – wily Jul 31 '13 at 15:45
1

Just don't use push. Add each other as remote and use git fetch/merge, cherry-pick, rebase or whatever you find appropriate to pull in each others contributions.

skorgon
  • 604
  • 4
  • 12
1

@cupcake's answer is fine, but there is nothing overkill about setting up a bare repo on your machine which acts as a central remote repository for both you and your friend. It's actually a lot simpler and makes life easier once its setup:

Prepare your new bare repository

mkdir newrepo
cd newrepo
git init --bare

Back to your existing repo:

git remote add new_repo_alias /path/to/newrepo
git push new_repo_alias something

Your friend does the same using ssh://..., but you have already figured out that part.

easy!

Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
  • thanks Sebastien, yes, a newrepo will work for sure; and let say I'm online for 1h so I want to commit everything, what is the best way to do it? like I pull everything from the newrepo, then change my remote repo to the official online one, push everything and then set back the newrepo as remote so we can continue to work without the official online repo? merci – wily Jul 31 '13 at 14:38
  • hi, best way to do that is simply adding the online repository as a second remote on your local one: `git remote add online-repo-alias url-of-online-repo`. Then just `git push online-repo-alias branchname` – Sébastien Dawans Jul 31 '13 at 16:04
  • Thanks Sebastien, I just started yesterday with Git, so still learning. thanks again. w – wily Aug 01 '13 at 00:04