You switch back and forth between branches using git checkout <branch name>.
And yes, git checkout -b NEW_BRANCH_NAME is the correct way to create a new branch and switching to it. At the same time, the command you used is a shorthand to git branch <branch name> and git checkout <branch name>.
Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it.
Create a branch at the point where master is, then checkout master and reset --hard to A More on reddit.com
r/git
13
5
April 24, 2025
ELI5: What really is Git branches, how to effectively use them, and whether or not we followed good git workflow.
In general, a branch is a separate version of your code while commits represent changes (as u/insertAlias pointed out, commits are not stored as whole separate versions of your code, just the differences from the previous commit). There are many philosophies on how to use git, so your branching model is going to determine the semantics of your branches. I think it's best to show by example: Let's say you're developing a game. Let's go with git-flow for git workflow. You would have a master branch, which would contain releases of your game which you publish on GOG or whatever. Then, you would create a new branch from master, develop. Here you would have the current development version of the game, which would contain stuff that isn't necessarily ready for release. Then, when you're happy with the changes you made on develop, it's time to get those changes to master. This is where pull requests and merging come in. In this situation, you would accomplish a merge simply by switching to master and pulling develop into master. This takes the changes you made on develop and tries to apply them to master. A better practice for when you're working with multiple people would be to create a pull request from develop into master. This basically says "hey, I have some changes in develop I want to put to master, whoever is in charge of master should take a look at them and merge them in if they like then". For the pull request, you would add some reviewers (like your boss or coworkers at work), and when they approve it, you can merge. You had a problem with merge conflicts. This is completely normal and it's not so intuitive for people starting with git. When multiple people work on the same codebase, it's inevitable that two people will change the same thing in different ways. If that happens and you try to merge, git basically says "hey, I can't figure out which of these changes should be the new state of the branch, I need you, the human, to help me figure it out". Let's say you pulled develop into master and there are conflicts. Then, your working copy of master will enter a "merging" state, where in places with conflicts, you will see both versions of the piece of code that is conflicted. You can then make edits to make it right (either pick one of the two versions, or you can keep both, or even mix and match). After you fix all these conflicts, you will do a commit and your changes will be successfully merged. From what I understood from your post, all three of you were working on the same branch, pushing directly to develop. This is not a good way of doing things, because what could happen is you start working on something, meanwhile someone else does something and pushes it to develop, and then when you try to push, it says NOPE, because your working copy is based on a commit that is not the latest on develop. That means you would have to painfully manually integrate your changes almost every commit, and imagine that on a team with 10+ devs. This is where feature branches of git-flow are useful. Let's say you guys want your game to have a feature of posting your score to Facebook. You talk about it and you decide that you personally will implement that. You then do a branch from develop and name it feature/add-facebook-integration or something like that. You will then do all the work needed to finish that feature, all on this branch. None of your colleagues will commit to this branch, so you don't have to worry about any conflicts until it's time to merge. So you can peacefully develop and test your new feature against some version of develop, until the feature is ready to go to develop. Then you either create a pull request or merge it directly, while resolving any merge conflicts in the merge commit (which is likely to happen if your feature takes some time to make and your colleagues did something in the meantime). So with three of you, you can see that all 3 can be working on 3 separate features, and you will not have any conflict problems, only once a feature is finished and needs to be merged with the other people's stuff. Fetching means just getting information about possible changes in the repository from the remote (for example from your Github.com repository). Pulling means taking the changes and actually putting them on your branch. Your colleagues could indeed work on your repo because you gave them the rights to do that, in practice, teams usually use some branching model where only a select few project leads are allowed to commit to develop and master, and all commits to these branches must be merge commits, which means that all development is happening on feature or similar branches, which are branched from develop, the dev does some work on it, and then makes a pull request for the repository administrators to review and potentially pull into develop. Here is an image I found within 10 seconds of googling showing a simple git history with master, develop and two feature branches. Note: I'm certainly not a "git ninja" and I massively oversimplified some things and completely omitted others, but there are a ton of great resources out there for learning git, so I encourage you to go out there and learn. If anyone finds any inaccuracies in my comment, please tell me, I'll be glad to learn something new as well. More on reddit.com
r/learnprogramming
4
3
October 22, 2018
The proper way to use branches?
This explains an accepted and generally good branching model: http://nvie.com/posts/a-successful-git-branching-model/
edit:
How is that not in the side-bar?
And, another take on it: http://drewfradette.ca/a-simpler-successful-git-branching-model/
Before creating a new branch, pull the changes from upstream. Your master needs to be up to date. ... When you want to commit something in your branch, be sure to be in your branch. Add -u parameter to set-upstream. ... The only difference is the: to say delete, you can do it too by using GitHub interface to remove branch: https://help.github.com/articles/deleting-unused-branches.
October 2, 2018 - LANG:bash echo a new line >> file.md git commit -a -m "Add a new line" echo yet another line >> file.md git commit -a -m "Add yet another line" echo one more line >> file.md git commit -a -m "Add one more line" echo this is the last line i promise >> file.md git commit -a -m "Add one last line" Imagine that after doing all this "work," you learn that, for whatever reason, you need to go back in time to when there were just two lines in the file and create new changes from then on. But at the same time, you must preserve the progress you already made. In other words, you want to create a branch from a past commit.
December 15, 2025 -The git branch command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again.
The default branch name in Git is master. As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically. Figure 11. A branch and its commit history · What happens when you create a new branch?
When creating a new branch, Git will automatically use the currently checked-out branch as a base. Let’s say our repository has two branches: main and dev.
Git branching intro. Create, list, rename, delete branches with git branch. git checkout: select which line of development you want and navigate branches
August 5, 2022 - You can create a Git branch using the git branch command followed by your desired branch name. See how you can create and checkout a branch with the same command...
May 14, 2026 - You may need to create a feature branch for focused and isolated development, a bugfix branch to address and test fixes separately, or an experimental branch to keep untested changes away from the main codebase. Everything depends on your needs. Using Git commands like git branch and git checkout, you can create and manage new branches within a version control system, initiating new features by creating new branches off the main branch.
March 23, 2021 - You currently selected branch will be highlighted green, and also denotable by the light-blue text in brackets on your command line. To create a branch, it’s as straightforward as typing git branch <name>. In this case I’ll be creating a ...
October 2, 2025 - As the creator of CoreUI, a widely ... developing new features. From my expertise, the most efficient approach is to use git checkout -b which creates and switches to a new branch in one command....
In Git, the main project is completed on the main branch. Making your first commit in a new git repository will automatically create a main branch. Create new branches from the main branch to develop new features for a project.
I've made some commits B, C, D to a master branch after commit A but later realized that this is a bigger change deserving a new branch.
So I checked out A and created branch "new" there. But of course the commits B, C, D are still part of "master", not "new." I know rebase is probably my friend here but I don't know how to use it in this scenario.
May 23, 2026 - Create a new Git branch with `git switch -c`, `git checkout -b`, or `git branch`. Modern syntax, naming conventions, tracking remotes, and cloning a...