How to fix pushed local and remote branch name easily on Git?

You created a branch and write some of the codes, pushed it to remote but suddenly you noticed that the branch name was incorrect! Ahh.. Don’t worry, you can change easily your branch name:

  • Firstly change the local branch name on your branch:
git branch -m new-name
  • Push that to remote:
git push origin :old-name new-name

Your old shitty branch and merge request will delete and you can open a new merge request with the same changes. You don’t lose your chances.

Here are some Git commands that will help:

br = branch name sb = source branch tb = target branch obr = old branch name nbr = new branch name

Basic Snapshotting

CommandDescription
git statusCheck status
git add [file-name.txt]Add a file to the staging area
git add -AAdd all new and changed files to the staging area
git commit -m "[commit message]"Commit changes
git rm -r [file-name.txt]Remove a file (or folder)

Branching & Merging

CommandDescription
git branchList branches (the asterisk denotes the current branch)
git branch -aList all branches (local and remote)
git branch [br]Create a new branch
git branch -d [br]Delete a branch
git push origin -D [br]Delete a remote branch
git checkout -b [br]Create a new branch and switch to it
git checkout -b [br] origin/[br]Clone a remote branch and switch to it
git branch -m [obr] [nbr]Rename a local branch
git checkout [br]Switch to a branch
git checkout -Switch to the branch last checked out
git checkout -- [file-name.txt]Discard changes to a file
git merge [br]Merge a branch into the active branch
git merge [sb] [tb]Merge a branch into a target branch
git stashStash changes in a dirty working directory
git stash clearRemove all stashed entries

Sharing & Updating Projects

CommandDescription
git push origin [br]Push a branch to your remote repository
git push -u origin [br]Push changes to remote repository (and remember the branch)
git pushPush changes to remote repository (remembered branch)
git push origin --delete [br]Delete a remote branch
git pullUpdate local repository to the newest commit
git pull origin [br]Pull changes from remote repository

Inspection & Comparison

CommandDescription
git logView changes
git log --summaryView changes (detailed)
git log --onelineView changes (briefly)
git diff [sb] [tb]Preview changes before merging

_Sources: _https://www.github.com/joshnh/Git-Commands/blob/master/README.md__

_Cover image: _https://svitla.com/blog/gitlab-vs-github__

Leave a Comment