1

I am new to GIT and GITHUB and was doing some hands-on and bit curious whats the best practices when working in the branch.

I did the following :

  1. Created a branch (lets say branch9).
  2. Added a new file, then git add , git commit.
  3. I didn't merge it with master "git merge master"
  4. Instead I used this cmd "git push origin master" (so pushing the contents directly to master instead of pushing it to branch9)
  5. I see some weird things. I created a pull request from GITHUB and merged the files to master but after few mins the merge disappears.

What is the correct sequence of steps I need to do while working on branching in GIT?

Do I need to merge the contents from branch9 to master in local repo (git merge master) and then git push origin master?

James Z
  • 11,838
  • 10
  • 25
  • 41
Rajeev Ghosh
  • 101
  • 9
  • 1. there are many possible workflows. Most of them are described in the freely available online git book. 2. No. – JB Nizet Feb 25 '18 at 11:29

1 Answers1

1

If you create a branch, you are supposed to push that branch:

git checkout -b branch9
# git add + commits
git push -u origin branch9

# some more commits
git push

Note the second push does not specify origin anymore: see "Why do I need to explicitly push a new branch?".

Then you can create a pull request from branch9 to master if you want, or if you are the only one working on the repo, you can merge locally your branch9 to master.
If there were no commits on master, that merge would be a fast-forward one, which explains why the merge disappear: master simply update itself to reflect branch9 HEAD.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283