Kenziiee Flavius Kenziiee Flavius - 5 months ago 12
Git Question

Git local branch auto merges

When i work on a git repo to do a quickfix i make a new local branch using

git checkout -b BRANCH_NAME
which makes the new branch i then work on that branch for a while and when im ready i do
git checkout dev
followed by
git merge BRANCH_NAME
to merge with the hotfix branch and i get the message
branch already up to date
.. which it shouldnt be because they are separate branches

This is bad because if something went wrong does that mean my dev branch would have already been updated? I have no idea why this is happening im still new to GIT so i would like for someone to explain what im doing wrong.


Basically what happens is since you do not add and commit your changes. When you carry out merge your dev branch will be up-to-date since as far as git system is concerned the branch you've created is the same as dev branch (nothing has changed).

In order to get things done properly, what you need to do is do a bit of work on your branch then add all this work using

git add <filename>.<extension>

or if they are already tracked

git add .

This instruction will put the file into a staging area. Think of it as if you would prepare a back-pack. Sometimes you would want put some stuff in it and sometimes you would take stuff out of it.

Then commit the work using

git commit -m "Describe here what you've done"

This will basically take a snapshot of your working directory on your local file system. Think of it as if you just completed putting everything in your back-pack.

go to your master branch dev

git checkout dev

This will simply switch you to the branch you've specified. In this case it's dev


git merge <branch>

Note: <branch> with whatever branch name you had been working on

Given you are on dev branch, this will merge the branch you are currently at (dev) with whatever branch you've specified in <branch> in the above instruction.