git branch

datajcthemax·2023년 6월 13일
0

git/github

목록 보기
4/18

In Git, a branch is essentially a unique set of code changes with a unique name. Each repository can have one or more branches. This allows you to move back and forth between different states of a project. For example, if you want to add a new feature or fix a bug, you can create a new branch and make the changes there. This keeps your main project (usually in the master or main branch) safe from potentially unstable code until it's been tested.

Here's a brief overview of how to work with branches in Git:

  • Creating a new branch: You can create a new branch using the command git branch <branch-name>. This creates a new branch but does not switch to it.

  • Switching to a branch: You can switch to a branch using the command git checkout <branch-name>. This updates the files in your working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

  • Creating a new branch and switching to it: You can do both of the above steps at once with the command git checkout -b <branch-name>. This creates a new branch and immediately switches to it.

  • Deleting a branch: You can delete a branch with the command git branch -d <branch-name>. However, Git won't let you delete a branch if it has commits that haven't been merged into another branch (to prevent you from losing work).

  • Merging branches: When you've finished working on a branch and the code is stable, you can merge it back into your main branch (or any other branch). You do this with the command git merge <branch-name>, which merges the specified branch into the current branch.

  • Viewing all branches: You can view a list of all your branches with the command git branch. This will show you which branch you're currently on and what other branches exist.

Branching is one of the key features of Git, and it's what allows multiple people to work on a project at the same time without stepping on each other's toes. It's also useful for working on multiple features at once or experimenting with new ideas without affecting the main project.

0개의 댓글