git reset --hard HEAD~1
- Affects local GIT repository only
- Discard local commits without keeping changes in files
git reset --soft HEAD~1
- Discard local commits while keeping changes in files
- 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 config --list # list all configs
- List git configurations
Creating a new repository
git add --all
git commit -m "Initial Commit"
git push -u origin master
Cloning an existing repository
git clone "firstname.lastname@example.org/etc/etc/repository.git"
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 remove server
- Re-apply Stashed changes
# stash staged files (option: -a, all files -u, un-tracked files)
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 remote repository. This will raise conflicts which 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