1

I am new to using GitHub to manage my projects, and I've decided to take up the challenge with a partner.

The question that I have, is that we work on the same branch, being master.

If my teammate makes changes to the branch and I've also made changes, how do I implement my changes to the master branch without losing my progress and keeping their progress?

I'm hoping there is a much more elegant solution than just copying my changes, implementing theirs into my local repo, then pasting my changes and committing again.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
robertmotr
  • 39
  • 1
  • 3
  • 1
    GitHub is not git. 1) Consider creating other branches 2) `origin/master` and `master` can differ, just merge the remote into yours before pushing – ti7 Nov 10 '20 at 03:47
  • 1
    Does this answer your question? [Make the current Git branch a master branch](https://stackoverflow.com/questions/2763006/make-the-current-git-branch-a-master-branch) – ti7 Nov 10 '20 at 03:50

1 Answers1

1

If you are working both on master(/ or main for new GitHub repositories), you can simply use git push

If it fails (because your teammates have pushed on master too), I would do a simple git pull, provided you have Git 2.6+ and the global setting:

git config --global pull.rebase true
git config --global rebase.autoStash true

That way, you are rebasing (replaying) your local commits done on your local master on top of the updated origin/master.
Once any merge conflict is resolved, and your program tested, you can push again.

Ideally though, your teammates would split their contribution across several branches instead of always pushing to master, which allows for an easier more stable workflow.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250