Chalic
Chalic

Reputation: 95

git branches are very confusing for me (creating new branches, features)

I've tried to create feature branch in GIT. What I trying to create

A -- B -- C ------ D
      \
       E -- 

Where first line is development, second line is feature branch.

How I need to create feature branch? Like this?

git checkout -d myFeature

After changing files:

git add .
git commit -m "My awesome commit"

And then push

git push origin myFeature

Merge in dev branch

git merge myFeature

And then commit and push again. Is this a right way?
Can a branch created from commit?
What means --track flag in GIT and when i need to use it?
What is the difference between branch and origin/branch?

Can somebody explain me about branches?

Upvotes: 0

Views: 139

Answers (1)

Jeff Puckett
Jeff Puckett

Reputation: 40841

How I need to create feature branch?

If you're trying to create myFeature branch from commit hash B

git checkout -b myFeature B

Note the syntax error in your posted question error: unknown switch 'd'

Merge in dev branch

Don't forget to checkout your dev branch first, and then merge myFeature

git checkout dev
git merge myFeature

And then commit and push again. Is this a right way?

No need to commit again, the successful merge will create the commit.

Can a branch created from commit?

Yes, as demonstrated in step 1

What means --track flag in GIT and when i need to use it?

I will refer you to the git branch documentation

-t, --track
    When creating a new branch, set up branch.<name>.remote and branch.<name>.merge configuration
    entries to mark the start-point branch as "upstream" from the new branch. This configuration will
    tell git to show the relationship between the two branches in git status and git branch -v.
    Furthermore, it directs git pull without arguments to pull from the upstream when the new branch
    is checked out.

    This behavior is the default when the start point is a remote-tracking branch. Set the
    branch.autoSetupMerge configuration variable to false if you want git checkout and git branch to
    always behave as if --no-track were given. Set it to always if you want this behavior when the
    start-point is either a local or remote-tracking branch.

What is the difference between branch and origin/branch?

branch should refer to your local copy, and origin/branch refers to the copy on the remote server.

Can somebody explain me about branches?

This is verging on off-topic for SO as too-broad, but here's a wonderful free interactive tutorial that should answer this for you in addition to the git book and the aforementioned git branch documentation.

Upvotes: 1

Related Questions