4. The [Un]necessary stuff¶
4.1. Renaming branches¶
4.1.1. Local¶
Just like creating a new branch, but adding the -m (move) flag.
$ git branch -m <Old-lame-name> <New-hot-name>
4.1.1.1. Rename current branch¶
$ git branch -m <New-hot-name>
4.1.2. Remote¶
There’s no easy way to do it...
# Remove the branch
$ git push origin :<Old-lame-name>
# Push the new branch
$ git push origin <New-hot-name>
4.2. Stash¶
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
4.2.2. Popping¶
Remove a single stashed state from the stash list and apply it on top of the current working tree state.
$ git stash pop
4.3. Patching¶
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.
$ git add -p <Filename>
$ git add --patch <Filename>
4.4. Rebase¶
Rebasing really is just moving a branch from one commit to another. But internally, Git accomplishes this by creating new commits and applying them to the specified base—it’s literally rewriting your project history.
-i- Make a list of the commits which are about to be rebased. Let the user edit that list before rebasing. This mode can also be used to split commits (see SPLITTING COMMITS below).
$ git rebase -i
4.5. Cherrypick[ing]¶
Apply the changes introduced by some existing commits.
$ git cherry-pick <Commit-ID>