git reset --hard HEAD^
Removing multiple commits from the top
Remove the last two commits:
git reset --hard HEAD~2
git push origin -f
~2
: up two levels in the hierarchy
if a commit has more than one parent, use the first parent
^2
: the second parent where a commit has more than one parent (i.e. because it's a merge)
HEAD~2^3
: HEAD's grandparent commit's third parent commit
git checkout develop
git fetch origin
git merge origin/master
git remote add upstream https://github.com/USERNAME/REPONAME.git
git remote rm upstream
check if it's gone: git remote -v
git fetch upstream
git checkout master
git merge upstream/master
git reset FILE
git reset
- discard all uncommitted changes
git reset --hard
git cherry-pick commitsSha
$ git remote -v
origin https://github.com/isinaltinkaya/REPO.git (fetch)
origin https://github.com/isinaltinkaya/REPO.git (push)
#change it to git
$ git remote set-url origin git@github.com:isinaltinkaya/REPO.git
- use soft links to sync your code in github repository directory with the working directory
ln -s /my/github/repo/dir/code.sh /my/working/dir/code.sh
bonus: you can use my bashrc script as well
add this to your .bashrc
:
lns(){
SRC=$(realpath ${1})
CDIR=$(pwd)
FNAME=$(basename ${1})
ln -vs ${SRC} ${CDIR}/${FNAME}
}
then
> cd my_working_dir
> lns ../../my_git_repo_dir/script
Will generate this soft link:
"/full/path/to/my_git_repo_dir/script" -> "/full/path/to/my_working_dir/script"
git submodule add https://github.com/samtools/htslib.git
clone repo with submodules:
git clone --recursive ${URL}
if already cloned:
git submodule init
git submodule update
if submodule contains another submodule: (with git v2.13 and later)
git clone --recurse-submodules ${URL}
if already cloned but missing a submodule of the submodule
git submodule update --init --recursive
with old version of git (v1.6.5 to v2.13)
git clone --recursive
cd submodule
git checkout v1
cd ..
git add . ; git commit -m "Changed submodule version to v1"; git push
git rm --cached MY_LARGE_FILES*
git commit --amend -C HEAD
git push
git config --global commit.template ~/.gitmessage
Inside .gitmessage
:
# [type](optional scope): Title
#################################################
# Title length: 50 chars - - - - - - - - - - -> #
#################################################
#
# Empty line between title and body
#
#
# Body: Explain *what* and *why* (not *how*)
# Body length: Wrap at 72 chars - - - - - - - - - - - - - - - - - -> #
#
#
# [type]:
# -------
# [feat] - A new feature
# [fix] - A bug fix
# [perf] - A code change that improves performance
# [test] - Add test
# [build] - Build related changes
# [chore] - Build process or auxiliary tool changes
# [doc] - Documentation-related changes
# [style] - Markup, formatting, typos etc
#
# Adapted from https://dev.to/helderburato/patterns-for-writing-better-git-commit-messages-4ba0
#