@@ -712,7 +712,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
712
712
int delete = 0 , rename = 0 , force_create = 0 , list = 0 ;
713
713
int verbose = 0 , abbrev = -1 , detached = 0 ;
714
714
int reflog = 0 , edit_description = 0 ;
715
- int quiet = 0 ;
715
+ int quiet = 0 , unset_upstream = 0 ;
716
716
const char * new_upstream = NULL ;
717
717
enum branch_track track ;
718
718
int kinds = REF_LOCAL_BRANCH ;
@@ -728,6 +728,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
728
728
OPT_SET_INT ( 0 , "set-upstream" , & track , "change upstream info" ,
729
729
BRANCH_TRACK_OVERRIDE ),
730
730
OPT_STRING ('u' , "set-upstream-to" , & new_upstream , "upstream" , "change the upstream info" ),
731
+ OPT_BOOLEAN (0 , "unset-upstream" , & unset_upstream , "Unset the upstream info" ),
731
732
OPT__COLOR (& branch_use_color , "use colored output" ),
732
733
OPT_SET_INT ('r' , "remotes" , & kinds , "act on remote-tracking branches" ,
733
734
REF_REMOTE_BRANCH ),
@@ -796,10 +797,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
796
797
argc = parse_options (argc , argv , prefix , options , builtin_branch_usage ,
797
798
0 );
798
799
799
- if (!delete && !rename && !edit_description && !new_upstream && argc == 0 )
800
+ if (!delete && !rename && !edit_description && !new_upstream && ! unset_upstream && argc == 0 )
800
801
list = 1 ;
801
802
802
- if (!!delete + !!rename + !!force_create + !!list + !!new_upstream > 1 )
803
+ if (!!delete + !!rename + !!force_create + !!list + !!new_upstream + !! unset_upstream > 1 )
803
804
usage_with_options (builtin_branch_usage , options );
804
805
805
806
if (abbrev == -1 )
@@ -865,6 +866,20 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
865
866
* info and making sure new_upstream is correct
866
867
*/
867
868
create_branch (head , branch -> name , new_upstream , 0 , 0 , 0 , quiet , BRANCH_TRACK_OVERRIDE );
869
+ } else if (unset_upstream ) {
870
+ struct branch * branch = branch_get (argv [0 ]);
871
+ struct strbuf buf = STRBUF_INIT ;
872
+
873
+ if (!branch_has_merge_config (branch )) {
874
+ die (_ ("Branch '%s' has no upstream information" ), branch -> name );
875
+ }
876
+
877
+ strbuf_addf (& buf , "branch.%s.remote" , branch -> name );
878
+ git_config_set_multivar (buf .buf , NULL , NULL , 1 );
879
+ strbuf_reset (& buf );
880
+ strbuf_addf (& buf , "branch.%s.merge" , branch -> name );
881
+ git_config_set_multivar (buf .buf , NULL , NULL , 1 );
882
+ strbuf_release (& buf );
868
883
} else if (argc > 0 && argc <= 2 ) {
869
884
if (kinds != REF_LOCAL_BRANCH )
870
885
die (_ ("-a and -r options to 'git branch' do not make sense with a branch name" ));
0 commit comments