-2

I want a similar structure to the below graph.

Say I clone a project from github which has a main branch.

I then want to create a server branch at the time which the main branch had its 2nd commit.

Would I create a branch off of my local branch main which clone the github main branch?

So would it look something like this?

git checkout -b main_local server

Then how would I update my main_local branch with server branch and then push the changes to reflect in the github main branch?

enter image description here

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Yogi Bear
  • 3
  • 4

1 Answers1

0

To create a branch on a previous commit (2nd commit of your main-branch), need this command:

# in main-branch
git checkout -b server <sha-of-2nd-commit>

To become the changes from server branch to your main branch, execute following command:

# change to main branch, when in server-branch
git checkout main

# merge server branch to main
git merge server

Attention: This can give merge conflicts, if you have in both branches change the same file at the same place (line).

After merging, type following to push the changes from local main-branch to remote main-branch:

# in main-branch
git push
SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
  • Very nice, for the first command i should be in the main local branch? – Yogi Bear Mar 14 '21 at 00:49
  • Yes in the `main` branch – SwissCodeMen Mar 14 '21 at 06:57
  • Hey i wanna aska question, say for example if i clone a project from Github on two different computers. If i create different branches on these computers will they show up for each other? – Yogi Bear Mar 14 '21 at 18:59
  • Simple answer: NO. For more, read this [git-branch tutotial](https://www.atlassian.com/git/tutorials/using-branches). But for other questions please ask a new question [here](https://stackoverflow.com/questions/ask). – SwissCodeMen Mar 14 '21 at 20:50