Collection of GIT commands.

Reset last changes (locally)

git reset --hard HEAD~1
  • Affects local GIT repository only
  • Discard local commits without keeping changes in files

Reset file last changes (locally)

git reset --soft HEAD~1
  • Discard local commits while keeping changes in files

Retrieve latest changes form remote repository

  • Pulls the latest changes from the current branch
  • This command will cause error when there are uncommitted changes and your local repository is outdated (i.e.: # commits behind)
git pull

List GIT configurations

 git config --list # list all configs 

Creating a new repository

git init  
git add --all 
git commit -m "Initial Commit"  
git push -u origin master 

Cloning an existing repository

  git clone ""

How to resolve merging conflicts

This example uses Visual Code and Gitlens but the principles should be applicable in other tools.  When multiple users are using the same repository code branch, it is common to encounter situations where there are conflicts in code between your local repository and the remote repository on GIT server.  Below are 2 ways to resolve this:

Revert, pull and apply changes

Revert all your local changes and re-apply the changes after retrieving the latest changes from the remote repository branch.

  • Stash your local changes
  • Pull latest from the remote server
  • Re-apply Stashed changes
# stash staged files (option: -a, all files -u, un-tracked files) 
git stash
git pull 

git stash pop # applies changes and remove stash 
git stash apply # OR applies changes but keep stash  

Commit, pull and merge

Commit all your local changes and pull the latest code from the remote repository. This will raise conflicts that you have to resolve before your code can be merged and sync back to the remote GIT server.

Stage and commit changes (locally)
git pull # pull changes, resolve conflicts and commit changes
Merge conflict as a result of conflicting changes between local/remote code files.

(source-stash commands)