Skip to content

Instantly share code, notes, and snippets.

@dohaivu
Last active December 14, 2018 08:45
Show Gist options
  • Save dohaivu/2152497716f10ca98662fdd21dbb2d41 to your computer and use it in GitHub Desktop.
Save dohaivu/2152497716f10ca98662fdd21dbb2d41 to your computer and use it in GitHub Desktop.
[git common commands] #git

https://help.github.com/articles/generating-ssh-keys/

Good message
Short summary(title): <50c A longer description of the changes follows: 72c

Git over LAN

git pull [email protected]:/Users/haivu/projects/shizzle

Set config

$ git config --global core.editor subl -w -n
$ git config --global user.name "Vu Do"
$ git config --global user.email "[email protected]"

# add key to agent
ssh-add -K ~/.ssh/id_rsa

# use specific key
git config core.sshCommand 'ssh -i /Users/localadmin/.ssh/ci-id_rsa' 

Remove files from git

git rm --cached FILE_NAME
git add -u
git commit -m "removing files from version control"
git push

Fetch

git fetch -p origin # fetch deleted branches

Rename

git mv README README.md
git commit -m "renamed"
git push origin master

Untrack files

git update-index --assume-unchanged [file]

Export

git archive master | tar -x -C /Users/haivu/projects/abc # to a directory
git archive --format zip --output /full/path/to/zipfile.zip master  # to a zip file

Cherrypick

git cherry-pick A^..B # cherrypick multiple

Detached head

git reflog
git log
git checkout master
git merge HEAD@{2}

Revert commit

git push origin +dd61ab32^:master # reset master to a commit

Undo commit

git reset --hard HEAD~1

Orphan branch New branch with no history

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "Initial commit"

Submodule

git submodule init
git submodule update -f # force update

# remove
git submodule deinit <path_to_submodule>
git rm <path_to_submodule>
git commit -m "Removed submodule "
rm -rf .git/modules/<path_to_submodule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment