Questions tagged [git-rebase]

With the git-rebase command, you can take the changes from one branch and replay them on top of another branch.

git rebase allows you to specify the starting point of a branch, that is, to "move" changes from a branch on top of another branch. You can also specify specific commits even if they don't have branches associated with them

The Git book has a chapter on rebasing has some nice examples with diagrams that help to understand the general concept, although each system has different capabilities.

Another common way to integrate changes is to merge to branches. The difference between these two operation has been covered in Stack Overflow:

Also on the usage of git svn the equivalent to git pull is a git svn rebase that rebases local changes ahead of the commits existing in the subversion repository.

A rebase can be undone as explained in "Undoing a rebase"

1640 questions
4214
votes
37 answers

How do I delete a commit from a branch?

How do I delete a commit from my branch history? Should I use git reset --hard HEAD?
hap497
  • 154,439
  • 43
  • 83
  • 99
4207
votes
19 answers

Undoing a git rebase

How do I easily undo a git rebase? A lengthy manual method is: checkout the commit parent to both of the branches create and checkout a temporary branch cherry-pick all commits by hand reset the faulty rebased branch to point to the temporary…
webmat
  • 58,466
  • 12
  • 54
  • 59
2309
votes
20 answers

When do you use Git rebase instead of Git merge?

When is it recommended to use Git rebase vs. Git merge? Do I still need to merge after a successful rebase?
Coocoo4Cocoa
  • 48,756
  • 50
  • 150
  • 175
1463
votes
17 answers

How to cherry-pick multiple commits

I have two branches. Commit a is the head of one, while the other has b, c, d, e and f on top of a. I want to move c, d, e and f to first branch without commit b. Using cherry pick it is easy: checkout first branch cherry-pick one by one c to f and…
tig
  • 25,841
  • 10
  • 64
  • 96
1371
votes
9 answers

How to rebase local branch onto remote master

I have a cloned project from a master branch from remote repository remote_repo. I create a new branch and I commit to that branch. Other programmers pushed to remote_repo to the master branch. I now need to rebase my local branch RB onto…
Damir
  • 54,277
  • 94
  • 246
  • 365
1062
votes
23 answers

How to remove/delete a large file from commit history in the Git repository?

I accidentally dropped a DVD-rip into a website project, then carelessly git commit -a -m ..., and, zap, the repo was bloated by 2.2 gigs. Next time I made some edits, deleted the video file, and committed everything, but the compressed file is…
culebrón
  • 34,265
  • 20
  • 72
  • 110
1039
votes
11 answers

Git workflow and rebase vs merge questions

I've been using Git now for a couple of months on a project with one other developer. I have several years of experience with SVN, so I guess I bring a lot of baggage to the relationship. I have heard that Git is excellent for branching and merging,…
Micah
  • 17,584
  • 8
  • 40
  • 46
736
votes
24 answers

How to squash all git commits into one?

How do you squash your entire repository down to the first commit? I can rebase to the first commit, but that would leave me with 2 commits. Is there a way to reference the commit before the first one?
Verhogen
  • 27,221
  • 34
  • 90
  • 109
669
votes
9 answers

Squash the first two commits in Git?

With git rebase --interactive you can squash any number of commits together into a single one. That's all great unless you want to squash commits into the initial commit. That seems impossible to do. Are there any ways to achieve…
kch
  • 77,385
  • 46
  • 136
  • 148
635
votes
8 answers

What's the difference between 'git merge' and 'git rebase'?

What's the difference between git merge and git rebase?
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
594
votes
6 answers

What is the difference between merge --squash and rebase?

I'm trying to understand the difference between a squash and a rebase. As I understand it, one performs a squash when doing a rebase.
GiH
  • 14,006
  • 13
  • 43
  • 56
562
votes
11 answers

Your branch is ahead of 'origin/master' by 3 commits

I am getting the following when running git status Your branch is ahead of 'origin/master' by 3 commits. I have read on some other post the way to fix this is run git pull --rebase but what exactly is rebase, will I lose data or is this simple way…
FluxEngine
  • 12,730
  • 14
  • 57
  • 83
485
votes
9 answers

Remove folder and its contents from git/GitHub's history

I was working on a repository on my GitHub account and this is a problem I stumbled upon. Node.js project with a folder with a few npm packages installed The packages were in node_modules folder Added that folder to git repository and pushed the…
Kartik
  • 9,463
  • 9
  • 48
  • 52
473
votes
2 answers

How do I git rebase the first commit?

I used git init to create a fresh repo, then made three commits. Now I want to rebase to go back and amend my first commit, but if I do git rebase -i HEAD~3 it shows error - fatal: invalid upstream 'HEAD~3'! If I try the same with HEAD~2 then it…
lxs
  • 8,847
  • 4
  • 20
  • 19
432
votes
5 answers

Rebase feature branch onto another feature branch

I have two (private) feature branches that I'm working on. a -- b -- c <-- Master \ \ \ d -- e <-- Branch1 \ f -- g <-- Branch2 After working on these branches a little…
Arjen
  • 5,043
  • 4
  • 18
  • 20
1
2 3
99 100