Reputation: 1410
I am learning git and I have a scenario:
So far from my understanding, at this point I can either:
I want to know if there is any better way of doing this.
Upvotes: 67
Views: 157549
Reputation: 1
My take is the key point is review the new commits on develop/main branch prior to decide doing a merge or rebase. There is no silver bullet that solves all the situations.
When the git framework is catching conflicts and initiate human-human interactions or discussions, the git is working properly as expected, git is a tool to help human work together effective.
Upvotes: 0
Reputation: 66430
If there are different changes on both the remote and the local branch, instead of just pulling the master by git pull
, I rather would do:
git pull --rebase
I even have it in my default config so that it will always will do a rebase if required on git pull
:
git config --global pull.rebase true
A rebase avoids a merge commit and keeps your changes on top of the current remote branch.
Yet you still have to resolve any occurring merge conflicts when different people are working on the same branch, which is a bad practice especially because it leads to conflicts.
(Also be aware that in the scope of a rebase, the meaning of theirs
and ours
is switched.)
In cases with minor changes, yours are just applied on the top.
You are changing the history, yet only your local one, not the remote's.
You won't need to git push --force
. You just git push
it as you are used to it.
In general, you should be working on feature branches and merge those back to the master branch.
When working on feature branches one can also keep the feature branch close to the master
by:
git checkout feature-branch
git fetch && git rebase origin/master
Yet here one would need to git push --force
the feature-branch, so one should be careful not to use this strategy if more than one person is working on the same feature-branch.
If one wants to use rebase and push forcing, consider using git push --force-with-lease
over git push --force
as it prevents accidentally deleting other's commits on the remote.
Upvotes: 72
Reputation: 51
Best way from my experience is:
That's how you can develop many new features and merge only the working ones when you need to deploy. Good luck and check this -> https://www.codeschool.com/courses/try-git
Upvotes: 5
Reputation: 5375
If you're both working on the same file(s), you'll inevitably run into conflicts. You'll just have to learn how to resolve conflicts.
If you want to avoid having to resolve conflicts, then maybe you guys should delegate tasks to each other that involve working on a different files.
Upvotes: 0
Reputation: 2660
One (simple*) way to handle this without branching or stashing:
Upvotes: 9
Reputation: 661
I believe git sync would be good. Git sync commits your changes, pulls any changes existing in master, then pushes all the changes together to master.
Upvotes: 2