Pergunta

I'm new to GIT and I think my merge wiped out some other people's work. Ouch.

I heard that its best to avoid the GIT merge workflow, and to rebase commits (locally) so you put your commits as clean commits on top of HEAD, on top of what other people have been doing, resulting in a fast-forward merge, which doesn't have all the merging going on.

But I don't really know what this entails. I want to do my commits in the safest way, I guess preferably without merges. So could anyone give a newbie like me some hints on playing it safe?

Thanks in advance!

Foi útil?

Solução 2

The thing I don't like about rebasing is if you are planning to do it you can't push your feature branches anywhere public otherwise someone could base some work on it and you get in trouble when you rebase and push the re-written history. So really you can only rebase stuff you haven't pushed anywhere.

It seems much simpler to me to branch off master to implement something. Push your branch if you want so others can see what you are doing and collaborate etc.

git checkout -b feature_branch
git push origin HEAD

If you're doing a significant chunk of work then every now and then:

git checkout master
git pull
gut checkout feature_branch
git merge master

Now your branch has any changes others push to master.

When you are done checkout master and make sure it's up to date again then:

git checkout master
git pull
git merge feature_branch
git push origin HEAD

So while your question is how to avoid merges perhaps my answer can inform you that you possibly don't need to do that...

Outras dicas

The way I do it

git checkout -b work

This creates a local branch called "work" which I commit to locally. I never commit to master. When I am done I do

git checkout master
git pull

To get the latest commits onto my master branch

git checkout work
git rebase master

I switch back to my work branch and rebase all the commits from master onto it.

git checkout master
git merge work

This should result in a fast-forward merge to master and then I just push

Might be a bit convoluted, but it works for me.

git pull --rebase 

Before you do any commit to the git branch.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top