sudo apt-get install git
Check git version
NOTE: Refer to git download on other platform.
Setup Git with Github
Create github account.
Setup username and email.
git config --global user.name "github_username" git config --global user.name "github_email"
git config --list
git config --edit --global
Add SSH key to github
Check if you already have a local SSH key. If yes,
~/.ssh/id_rsa should exist.
ls -al ~/.ssh
If you don’t have a local SSH key, generate one.
ssh-keygen -t rsa -b 4096 -C "any identifier: email, etc."
NOTE: I would recommend to use a passphrase
Add SSH key to ssh-agent
List all ssh-agent keys.
Copy content of
sudo apt-get install xclip xclip -sel clip < ~/.ssh/id_rsa.pub
Paste SSH key to Github. Visit Github, click to top right user profile icon, then
Settings -> SSH and GPG keys -> New SSH Keys.
NOTE: Refer to Connecting to GitHub with SSH.
Create New Github Repository
Visit Github, click on the top right
+ icon (left of user profile icon) and select
New Repository. Fill in the following:
- Name: e.g.
- Description: optional
- Initialize this repository with a README (checked this if you haven’t created the project files on your computer yet)
- Add .gitignore: e.g. select
pythonif you are doing a python project
- Add license: if this is a public project, 3 common choices are
Apache License 2.0,
GNU General Public License v3.0,
MIT License. For private project, you can select
NOTE: Refer to Which License for Sample Code for license reference.
Checkout a Github Repository
Download/Clone the Github repository to a local directory.
Run the following in your workspace directory.
git clone firstname.lastname@example.org:USERNAME/git-test.git
NOTE: The above will create
git-test directory in the current directory.
NOTE: You can rename
git-test directory with
git clone email@example.com:USERNAME/git-test.git NEW_DIR_NAME.
NOTE: If you prefer to create a local git repository without cloning existing remote repository, use
Add, Commit & Push
- Add: start tracking a file
- Commit: commit to local repository (revision log created)
- Push: push changes to remote repository (e.g. Github)
Check current git status
Add new file
git add test.py
Add all files (new, modified, deleted).
git add -A
git add --all or
git add . has the same effect.
Commit all tracked files.
git commit -m "Commit #1"
NOTE: Comment/Message for commit are mandatory. You can use
git commit -m. (
. as message) or
git commit -am'save' (
save as message).
NOTE: Some might use
git commit -am 'message' to combine
commit, but this only affect files that have been modified and deleted, but doesn’t affect new files.
Push all committed changes to server.
git push origin master
Sometimes you want to work on a big feature which might take more than one day, yet you still want access to the original source (before modification) still be accessible and stable.
Create a new branch and switch to the branch.
git checkout -b sprint-01
Show available branch and current branch.
master * sprint-01
Push branch to remote server (e.g. Github)
git push origin sprint-01
git checkout master
git branch -d sprint-01
Once your work on the branch is completed and tested, you can merge it with the master.
Assuming you are working in the branch (e.g.
sprint-01). You can check your current branch
Check diff with master (assuming you are still in
git diff master
Merge current branch with master
git checkout master # Switch to `master` branch git pull # Optional: get latest update from remote repository git merge sprint-01 # Merge `master` with `sprint-01` git push origin master # Update merged `master` to remote repository
Tag is usually used for release. It is like a save point, where we can refer back to this point for deployment or testing.
git tag -a 0.1 -m "Message for 0.1"
Update tag to remote repository.
git push origin 0.1
Show created tags.
git tag -d 0.1
This is a very basic guide suited for single user.
Git is quite simple to get started, but hard to master especially when there are more users in a single project.