Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Create and List Local and Remote Git Branches - DesignLinux

Aug 22 2020
designlinux 0 Comments
Create and List Local and Remote Git Branches

In Git, a branch is simply a lightweight movable pointer to commits and a part of development process. At the time of development the developers are creating a new branch that later can be merged in to the production codebase. In this article we will show you how to create and list local and remote Git branches.

List Git Branches#

Use the git branch or git branch --list command to list all local Git branches:

  dev
  stagging
  hotfix
* master

The asterisk (*) indicates that is the current branch. In above example master is the current branch.

To list the both local and remote branches pass -a option with the command:

git branch -a
  dev
  stagging
  hotfix
* master
  remotes/origin/dev-a

You can use -r option to list only the remote branches:

git branch -r

Creating a Git Branch#

It’s very easy to create a branch, to create a local branch use the git branch command followed by the name of the new branch. For example, to create a new branch with name test-branch, you would type:

git branch test-branch

It will not return anything output. If the branch with same already exists it will show a error message like below:

fatal: A branch named 'test-branch' already exists.

Ensure that before working on branch, you should select the branch using git checkout command followed by the branch name:

git checkout test-branch

In output it will print message that the branch is switched:

Switched to branch 'test-branch'

If you would like to create a branch and switched to it using one command, you can do it using the -b option with git checkout command:

git checkout -b test-branch
Switched to branch 'test-branch'

Now, your branch is selected and you can now use the git add and git commit commands to add commits to the new branch.

Push the new branch on the remote repository, use the git push command followed by the remote repository name and branch name:

git push remote-repo-name test-branch

Conclusion#

We have show how to create local and remote Git branches. With the git branch command, you can also Rename and Delete local and remote Git branches.

If you have any questions or suggestion, please leave a comment below.

Related

Tags: git

How to Add and Remove Users on Ubuntu 20.04

Prev Post

How to Install Slack on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 1
  • 64
  • 605,814

DesignLinux.com © All rights reserved

Go to mobile version