How to use git branches for project functions?

I am working (one) on a project that needs to add several functions. I use to create a branch for each function. After the function has been developed and well tested, I combine this branch with the main branch.

Now I run the function (let it enable function A) on branch-A, which is not finished yet. However, I urgently need to create a new function B and press it before the completion of function A. That's why I created branch-Band switched to it.

However, by running the command git status, I can see all the changes that I made in branch-A. I do not understand this default behavior. I expected to see “no change” because they are different industries. I absolutely need the commit in branch B to ignore everything I do in branch A.

What am I missing? How to create the right workflow?

+4
source share
3 answers

You did not make your changes in branch-Aand switched to branch-B, so you got all this mess.

To avoid this behavior, temporarily save your changes to branch-Aor stash .

+2
source

, branch-A, . .

:

# Switch back to branch-A
git checkout branch-A

# Check the status
git status

# Add all of the changes
git add .

# Commit the changes
git commit -a

# Switch back to branch-B
git checkout branch-B

# Check git status
git status

( git stash), branch-A:

# Switch back to branch-A
git checkout branch-A

# Create a new branch
git checkout -b branch-A-temp

# Add all of the changes
git add .

# Commit the changes
git commit -a

# Switch back to branch-B
git checkout branch-B

# Check git status
git status

branch-A-temp . , branch-A.

- . - , . , , .. .

0

, branch B, branch A. branch B branch A. branch B, master.

git checkout -b new-feature master
0

Source: https://habr.com/ru/post/1599858/


All Articles