Technical notes‎ > ‎

Version Control (Git, Subversion SVN, etc.)

posted Nov 26, 2014, 12:57 AM by Le Tuan Anh   [ updated Aug 2, 2017, 10:58 PM ]

Git

Clone from github (and submodules)

git clone --recursive https://github.com/user/foo

Add a submodule into a repository

git submodule add https://github.com/user/foo.git
git submodule init
git submodule update

Remove a submodule

git submodule deinit -f -- modules/submodule   
rm -rf .git/modules/a/submodule
git rm -f a/submodule


Undo modification
git checkout -- [filename]

Update submodule to latest version

git fetch && git checkout master && git merge origin/master

Generate SSH key for passwordless push to Github

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

ls -al ~/.ssh
ssh-keygen -t rsa -C "account@gmail.com"

# Now add key to Github account (~/.ssh/id_rsa.pub)
https://github.com/settings/ssh

# Test connection
ssh -T git@github.com

# Update the repository remote URL to SSH
git remote set-url origin git@github.com:username/REPO.git
git remote -v

To remember passphrase:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Undo stuff (Source | Cached)

git checkout <commit-id>
View a previous commit.
git tag -a <tag-name> -m "<description>"
Create an annotated tag pointing to the most recent commit.
git revert <commit-id>
Undo the specified commit by applying a new commit.
git reset --hard
Reset tracked files to match the most recent commit.
git clean -f
Remove untracked files.
git reset --hard / git clean -f
Permanently undo uncommitted changes.

Archiving a repository

git archive --format zip --output dist/code-trunk.zip master

[To be updated]

Comments