Skip to content
Andres Olarte edited this page Oct 26, 2017 · 7 revisions

Amend

git commit --amend
git push origin my_branch --force

If the commit that is amended has already been pushed, then --force is needed when pushing.

Branch

Create branch and checkout

git checkout -b my_branch origin/master

Checkout

Checkout file from a different branch

git checkout master -- my.file

Fork a repo

git remote add upstream https://github.com/remote/remote.git
git fetch upstream
git merge upstream/master
git push origin master

Merge

Merge from master into feature1

git checkout feature1
git merge master 

Rebase

  1. Fetch recent version git fetch origin
  2. Rebase git rebase origin/master
  3. Resolve conflicts
  4. Mark conflicts resolved git add .
  5. Continue the rebase git rebase --continue
  6. Push to origin git push origin my_branch --force

Remotes

Show remotes

git remote -v

Change remotes

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

Revert commit

Revert the last commit

git reset HEAD~

Squash

To squash interactively

git rebase -i HEAD~3

Where 3 is the number of most recent revisions that will be up for squashing

Submodules

Init the submodule

git submodule update --init --recursive

Update from upstream

git remote add upstream https://github.com/remote/remote.git
git fetch upstream
git rebase upstream/master
Clone this wiki locally