Made a typo or wrong description in a commit message? Run and edit:
git commit --amend
git commit --amend --reuse-message HEAD
#or
git commit --amend --no-edit
git reset <filename>
If you already have committing the file:
git reset --soft HEAD~1
get reset <filename>
rm <filename>
git commit
git tag v0.11.1
git tag -d v0.11.1
# all stage-v0.2.x
git tag -d `git tag | grep -E 'stage-0.2..*'`
git remote add upstream <original-repo>
git fetch --tags upstream
git push --tags
git branch
git checkout -b newbranch
git branch -m <oldname> <newname>
#If you want to rename the current branch, you can do:
git branch -m <newname>
git branch -d <branchname>
# To force delete use -D
# List all remote
git branch -r
# Checkout
git checkout -b LocalName origin/remotebranchname
git checkout master
git merge <featurebranch>
git checkout <featurebranch>
git rebase master
git fetch --all
git reset --hard origin/master
#git reset --hard origin/<branch_name>
git remote -v
#origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
#origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git remote -v
#origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
#origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
#upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
#upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
git fetch upstream
git checkout master
git merge upstream/master
git fetch origin pull/ID/head:BRANCHNAME
git checkout BRANCHNAME
git push origin BRANCHNAME
#or merge
git branch --set-upstream-to=origin/BRANCHNAME BRANCHNAME
git pull
#resolve
Rebase a remote branch locally (named devel)
git checkout devel
git fetch upstream
git merge upstream/devel
# or??
git rebase devel upstream/devel
git reflog
Review the output. Find the commit/item and note the identification number, e.g. 3a5f876. Now reset the git HEAD:
git reset HEAD@<identification number>
curl -i https://git.io -F "url=https://github.com/..."
Credit: https://github.com/tinc2k/cheatsheets/blob/master/git.md
Setup
Settings can be saved in
/etc/gitconfig
,~/.gitconfig
or<repository>/.git/config
Init/clone
Staging
Commit
Commits represent every saved version of a project, containing the snapshot of the project, user info, date, commit message & SHA-1 checksum of it's entire contents.
Recommended commit message:
Undoing changes
Branches
Merging
Merge methodologies
Merge methodology is determined from the structure of your history. There are 2 basic types:
Merge conflicts
Branching workflows
Most common types of branches:
Rebasing
Rebase means moving the entire branch onto a new base, which makes it a linear extension of the new base.
With the rebase command, you can take all the changes that were committed on one branch and replay them on another one.
NEVER rebase a branch that has been pushed to a public repository.
Remote Repositories
Remotes are nothing more than bookmarks to other repositories—instead of typing the full path, they let you reference it with a user-friendly name.
Commits may be the atomic unit of Git-based version control, but branches are the medium in which remote repositories communicate. Remote branches act just like the local branches we’ve covered thus far, except they represent a branch in someone else’s repository.
Remote Workflows
There is no “master” repository according to Git as there is with SVN or CVS. The “official” code base is merely a project convention—the only reason it’s the official repository is because that’s where everyone’s origin remote points.
Public (Bare) Repositories
Collaboration assumes the existence of at least one public repository, and those have to be bare - they must not have a working directory to prevent developers from overwriting each others' work with
git push
. These are initiated withgit init --bare some-repo.git
.Centralized Workflow
Integrator Workflow
stash
etc
TODO
references
https://github.com/mmihaljevic/cheat_sheet/blob/master/git
http://git-scm.com/book/en/Git-Branching-Rebasing
https://www.atlassian.com/git/tutorial/git-basics#!overview
http://wildlyinaccurate.com/a-hackers-guide-to-git