Skip to content

Instantly share code, notes, and snippets.

@ckdanny
Last active August 21, 2020 05:56
Show Gist options
  • Save ckdanny/0eb9526a87b73b4a17d6d07dc009ab5b to your computer and use it in GitHub Desktop.
Save ckdanny/0eb9526a87b73b4a17d6d07dc009ab5b to your computer and use it in GitHub Desktop.
[Git Common Command]

[TOC]

Patch

Git provides 2 ways to patch the repo, git format-patch and git diff

diff

also available in source tree

format-patch

Cherry-pick

Provide a method to selectively add the commits to the current branch.

# First checkout the target branch
$ git checkout <branch name>

# pick the commit and assign to the current branch
$ git cherry-pick <hash_id>

To cherry-pick all the commits from commit A to commit B (where A is older than B), run:

$ git cherry-pick A^..B

If you want to ignore A itself, run:

$ git cherry-pick A..B

Mirror

$ git clone --mirror xxx.git
$ git push --mirror xxx.git

Submodule in Git

$ git submodule add xx.git {folder}

You may need to init after pull

$ git submodule init

Git global setup

git config --global user.name "xxx"
git config --global user.email "xxx"

Create a new repository

git clone git@hxxx:xxx.git
cd xxx
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

cd existing_folder
git init
git remote add origin git@hxxx:xxx.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin git@hxxx:xxx.git
git push -u origin --all
git push -u origin --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment