GIT Help
################### Configurations ####################
# Make ssh connection with github (from Debian)
- Generate public/private key pair on local computer
cd ~/.ssh
ssh-keygen -t rsa -C "your_email@example.com"
- Add private key to the local ssh-agent
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
- Copy public key to clipboard
clip < ~/.ssh/id_rsa.pub - Linux
pbcopy < ~/.ssh/id_rsa.pub - Unix
- Add public key to Github
https://github.com/settings/ssh
- Check ssh connection with github
ssh -T git@github.com
# When git asking username and password every time you commit, then you have cloned the repository using https rather using ssh. To correct that mistake
git remote set-url origin git@github.com:dilumdarshana/AngularJS.git
# When git contribution does not show on the profile graph do this,
# git config : To config settings
eg. git config --global user.name = 'Dilum Darshana';
git config --global user.email = 'dilum.dar@gmail.com';
################# General Commands #########################
# git --version : To check git available on local
# git init : Initialize repo in local
# git remote add origin GIT_PATH : Add remote location to the local repo
# git clone GIT_PATH : Clone git repo from remote
# git status : Check repo status in local
# git add <file name> : Add files to local repo
eg. git add file1 file2 - add specific files to repo
# git commit -m <track message> : Commit files
# git push origin <branch_name> : Push files to remote
eg. git push origin master
# git pull origin <branch_name>: Update local repo
# git commit --amend : amend current changes to the previous commit
---------- Other Commands ------
# git mv <old_file_name> <new_file_name> : Rename file/folder
---------- Reset Files ----------------
# git reset --hard <git log ID> : reset repository to the given git stage. This will completely remove local changes. Log ID can get from 'git log'
# git reset --soft <git log ID> : same as above. This will not remove local changes
# git reset HEAD <file name> : Remove added files from git (this can not reset files which committed)
# git checkout -- <file_name> : to discard current changes
---------- Branching -----------
# git branch <branch_name> : Create branch on local. Will switch to this branch automatically
# git branch : List down all local available branches
# git checkout <branch_name> : Switch to branch on local
# git checkout -b <branch_name> : Create new branch and switch into that
# git branch -m '<new_branch_name>' : Rename branch, when on the branch
# git push origin :<old_branch_name> <new_branch_name> : After rename, make remote branch change
# git branch -d <branch_name> : Delete branch
---------------- Stashing ----------------
# git stash : To stash away current changes
# git stash list : To list down all the available stashes
# git stash apply : To apply last stash to current repo
# git stash apply <stash identifier> : To apply specific stash. Stash identifier can take from 'git stash list'
# git stash drop : To destroy all stashes
------------ Tagging -----------------
# git tag -a <version_number> -m <comment> : Create a tag
git push --tags
------------ Merging ----------------
------------ Debugging -------------
# git log : To see git local history
# git show <git log ID> : to see the changes for given log ID
# git branch -v : to see what is the latest change for each branch
------------- Create Command shortcuts -----------
git config --global alias.s status : short form works for 'git s'
Note: these configurations will be stored in file located at '~/.gitconfig'
------------- Git Ignore -------------
# Ignoring files
Create a files with name .gitignore and add files/directories that need to ignore on that file
General set of files need to ignore for main projects can be found from
https://github.com/github/gitignore
Good tutorial can be found from, https://help.github.com/articles/generating-ssh-keys
# Make ssh connection with github (from Debian)
- Generate public/private key pair on local computer
cd ~/.ssh
ssh-keygen -t rsa -C "your_email@example.com"
- Add private key to the local ssh-agent
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
- Copy public key to clipboard
clip < ~/.ssh/id_rsa.pub - Linux
pbcopy < ~/.ssh/id_rsa.pub - Unix
- Add public key to Github
https://github.com/settings/ssh
- Check ssh connection with github
ssh -T git@github.com
# When git asking username and password every time you commit, then you have cloned the repository using https rather using ssh. To correct that mistake
git remote set-url origin git@github.com:dilumdarshana/AngularJS.git
# When git contribution does not show on the profile graph do this,
git config --global user.email "YOUR EMAIL ADDRESS"
# git config : To config settings
eg. git config --global user.name = 'Dilum Darshana';
git config --global user.email = 'dilum.dar@gmail.com';
################# General Commands #########################
# git --version : To check git available on local
# git init : Initialize repo in local
# git remote add origin GIT_PATH : Add remote location to the local repo
# git clone GIT_PATH : Clone git repo from remote
# git status : Check repo status in local
# git add <file name> : Add files to local repo
eg. git add file1 file2 - add specific files to repo
# git commit -m <track message> : Commit files
# git push origin <branch_name> : Push files to remote
eg. git push origin master
# git pull origin <branch_name>: Update local repo
# git commit --amend : amend current changes to the previous commit
---------- Other Commands ------
# git mv <old_file_name> <new_file_name> : Rename file/folder
---------- Reset Files ----------------
# git reset --hard <git log ID> : reset repository to the given git stage. This will completely remove local changes. Log ID can get from 'git log'
# git reset --soft <git log ID> : same as above. This will not remove local changes
# git reset HEAD <file name> : Remove added files from git (this can not reset files which committed)
# git checkout -- <file_name> : to discard current changes
---------- Branching -----------
# git branch <branch_name> : Create branch on local. Will switch to this branch automatically
# git branch : List down all local available branches
# git checkout <branch_name> : Switch to branch on local
# git checkout -b <branch_name> : Create new branch and switch into that
# git branch -m '<new_branch_name>' : Rename branch, when on the branch
# git push origin :<old_branch_name> <new_branch_name> : After rename, make remote branch change
# git branch -d <branch_name> : Delete branch
---------------- Stashing ----------------
# git stash : To stash away current changes
# git stash list : To list down all the available stashes
# git stash apply : To apply last stash to current repo
# git stash apply <stash identifier> : To apply specific stash. Stash identifier can take from 'git stash list'
# git stash drop : To destroy all stashes
------------ Tagging -----------------
# git tag -a <version_number> -m <comment> : Create a tag
git push --tags
------------ Merging ----------------
------------ Debugging -------------
# git log : To see git local history
# git show <git log ID> : to see the changes for given log ID
# git branch -v : to see what is the latest change for each branch
------------- Create Command shortcuts -----------
git config --global alias.s status : short form works for 'git s'
Note: these configurations will be stored in file located at '~/.gitconfig'
------------- Git Ignore -------------
# Ignoring files
Create a files with name .gitignore and add files/directories that need to ignore on that file
General set of files need to ignore for main projects can be found from
https://github.com/github/gitignore
Good tutorial can be found from, https://help.github.com/articles/generating-ssh-keys