LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2015, 01:13 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
git - is there a way to move a branch short of deleting/recreating it?


If you want to move the branch that is checked out, moving this branch is fairly simple:

Code:
git reset --hard somewhere
But is there a way to do this on a branch that is not checked out? It would be possible this way:

Code:
git branch -D aBranch
git branch aBranch somewhere
Can it be done in a single shot?

Thanks in advance.
 
Old 06-18-2015, 08:19 AM   #2
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 486

Rep: Reputation: 206Reputation: 206Reputation: 206
Code:
git branch -m old-name new-name
or if you have the branch checked out:
Code:
git branch -m new-name
 
Old 06-18-2015, 10:50 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
Also, remember that "git always 'moves forward.'" Your actions will result in yet another git transaction.
 
Old 06-18-2015, 11:34 AM   #4
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 217

Rep: Reputation: 68
Quote:
Originally Posted by mina86 View Post
Code:
git branch -m old-name new-name
or if you have the branch checked out:
Code:
git branch -m new-name
Sorry, but I don't understand - what is this supposed to do here? IMO OP used "rename" incorrectly - as we see in his post, he uses "git reset" command. What he wants to do is move a tip of aBranch branch to a different commit and not rename aBranch.
 
Old 06-18-2015, 03:08 PM   #5
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 486

Rep: Reputation: 206Reputation: 206Reputation: 206
Ah, in that case:
Code:
git branch -f branch-name ref-to-move-the-branch-to
 
1 members found this post helpful.
Old 06-18-2015, 04:18 PM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Original Poster
Rep: Reputation: 90
Haven't tried yet but reading git manual, I think the -f option will do the trick. Thanks, mina86.
 
  


Reply

Tags
branch, git, move, reset


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
git: committed to wrong branch hydraMax Programming 2 04-19-2013 10:13 PM
How to Git delete a branch? binladen_vn88 General 4 01-21-2013 12:55 AM
git branch changes are changing master? joejoe99 Linux - Software 2 05-01-2012 03:56 PM
How can i update kernel source from git with my own changes in another branch Richard.Yang Linux - Software 16 09-25-2011 01:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration