Technical notes‎ > ‎

Version Control (Git, Subversion SVN, etc.)

posted Nov 26, 2014, 12:57 AM by Le Tuan Anh   [ updated Jan 21, 2021, 10:24 PM by Le T. ]


Basic Git commands

Clone from github (and submodules)

git clone --recursive

To check out a specific branch to a local folder, use

git clone --recursive --branch branch_name repo_name

To update current local copy (local Git repo), use pull command

git pull origin master

Stage a file - i.e. mark changed files (newly created/modified/deleted) to be committed

git add folder_name/

Commit change(s) to local repository (the quoted part after -m is commit message)

git commit -m "Lorem ipsum - I changed these files for good"

Push changes to the branch master on the remote repository (e.g. Github) origin

git push origin master

to unstage uncommitted changes, use

git reset path/to/

Advanced commands

Add a submodule into a repository

git submodule add
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


ls -al ~/.ssh
ssh-keygen -t ed25519 -C ""
ssh-keygen -t rsa -b 4096 -C ""

# Now copy the content of the public key file (~/.ssh/ and create a new SSH key on your Git server

# Test connection
BitBucket: ssh -T
ssh -T

# Update the repository remote URL to SSH
git remote set-url origin
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 tag -d <tag-name>
Delete a specific tag locally
git push --tags
Push local tags to remote server
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/ master

[To be updated]