Git Branch

Contents
branch: Branches
Create a new branch
checkout: Change branch
-d: Delete branch
-m: Rename branch
Update branch from remote repository
Other Git articles

Branches

See which branch is currently active

$ git branch

* master

Before creating a new branch, you need to make sure that there are no unsaved changes in the old one.

$ git status

On branch master
nothing to commit, working tree clean

Also if you are, for example, in master first do

git pull

To ensure that the new branch is branched off from the most recent version of master

Create a new branch

To create a new branch, run

$ git branch new-branch

Check if it appeared on the list

$ git branch

* master
new-branch

Перейти в новую ветку

$ git checkout new-branch

Switched to branch 'new-branch'

Return to master branch

$ git checkout master

If you made some changes in the new-branch branch, committed them and now want to add these changes to the master branch, you need to run the merge command

$ git merge new-branch

Updating f521fc5..fe7276a
Fast-forward
index.html | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

You can create a new branch and immediately move to it with one command

$ git checkout -b new-branch-2

Delete branch

Delete local branch

git branch -d branchName

Deleted branch branchName (was 1ce400ce6).

Delete external branch

git push origin --delete remoteBranchName

Rename branch

To rename a branch, go into it, make sure you are in the root of the project and run

git branch -m newName

Replace newName with the name you need.

Update a branch from a remote repository

If your local branch has lagged behind the remote repository and needs to be updated, run git pull.

git pull origin ИМЯ_ВЕТКИ

This can happen if you created a branch on one computer, pushed to a remote repository (github, gitlab…) then moved to this branch on a second computer, pushed from there and returned to the first computer. The local branch does not have the latest commits, so you need to download them with the following command.

git pull origin topic/qa/HH-2398_update_malaga_hotels

From gitlab.heihei.com:HEI/HEI * branch topic/qa/HH-2398_update_malaga_hotels -> FETCH_HEAD Updating 095a284bd..43cd9724d Fast-forward src/countries/spain/malaga/index.php | 26 ++++++++++++++++++++++---- src/countries/spain/costa-del-sol/index.php | 24 ++++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-)

Related Articles
Git
Установка в Windows
Установка TortoiseGit
.gitignore
Необходимые Bash команды
Errors
Development
DevOps
SSH
Работа с API GitHub
Banner Image

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat