Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

create local and remote branch

git checkout -b yourBranchName
git push -u origin yourBanchName
Comment

create new remote branch

git checkout -b <new-branch-name>	#Create new branch locally
git push <remote-name> <new-branch-name> #Create new branch remotely
Comment

create branch from remote branch

Updated for Git 2.23: For older versions, see the section at the end.

With One Remote
In both cases, start by fetching from the remote repository to make sure you have all the latest changes downloaded.

$ git fetch
This will fetch all of the remote branches for you. You can see the branches available for checkout with:

$ git branch -v -a

...
remotes/origin/test
The branches that start with remotes/* can be thought of as read only copies of the remote branches. To work on a branch you need to create a local branch from it. This is done with the Git command switch (since Git 2.23) by giving it the name of the remote branch (minus the remote name):

$ git switch test
In this case Git is guessing (can be disabled with --no-guess) that you are trying to checkout and track the remote branch with the same name.

With Multiple Remotes
In the case where multiple remote repositories exist, the remote repository needs to be explicitly named.

As before, start by fetching the latest remote changes:

$ git fetch origin
This will fetch all of the remote branches for you. You can see the branches available for checkout with:

$ git branch -v -a
With the remote branches in hand, you now need to check out the branch you are interested in with -c to create a new local branch:

$ git switch -c test origin/test
For more information about using git switch:

$ man git-switch
I also created the image below for you to share the differences, look at how to fetch works, and also how it's different to pull:

enter image description here

Prior to Git 2.23
git switch was added in Git 2.23, prior to this git checkout was used to switch branches.

To checkout out with only a single remote repository:

git checkout test
if there there are multiple remote repositories configured it becomes a bit longer

git checkout -b test <name of remote>/test
Comment

How to createe git remote branch

git checkout -b <branch-name> # Create a new branch and check it out
git push <remote-name> <branch-name> 
Comment

git link local branch to remote branch

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
Comment

create branch from remote branch

$ git switch -c test origin/test
Comment

create local git branch from remote

git checkout -b localName remoteName
Comment

create a new remote branch based on local

$ git push -u origin <branch-name>
Comment

PREVIOUS NEXT
Code Example
Shell :: bitbucket Permission denied (publickey). fatal: Could not read from remote repository. 
Shell :: install choco 
Shell :: cmake source directory 
Shell :: how install mongodb on raspberry 
Shell :: merge csv files powershell 
Shell :: grep or match 
Shell :: wget destination filename 
Shell :: first commit github 
Shell :: logging output in bash scripts 
Shell :: ssh rembeber password 
Shell :: ubuntu edit swap m 
Shell :: install npm packages on shared hosting 
Shell :: set nemo as default ubuntu 
Shell :: how to update packages in arch linux 
Shell :: how to setup a command that install all npm modules, in subfolders 
Shell :: scp 
Shell :: ubuntu deskyop repository 
Shell :: gh_token environment variable powershell 
Shell :: installed delphi package says unit not found 
Php :: symfony schema update 
Php :: larave whereNotNull 
Php :: generate random unique hex color code using php 
Php :: make specific migration laravel 
Php :: how get the latest data in database in laravel 
Php :: deactivate woocommerce breadcrumbs 
Php :: autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated. 
Php :: hasany cakephp 
Php :: php reading a file line by line 
Php :: wp_dequeue_style 
Php :: create laravel project specific version 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =