Pre-requisites: git is installed on your machine having admin rights. Git – Downloads (git-scm.com)
Exercise Caution: Understand the git commands and their outcomes; before running them on your machine
Quick setup steps: Identifying yourself for the codes you modify
- Create a project on your local machine: do > git init
- Create a github repo against your account at https://www.github.com
- Identifying yourself on your local machine
git config –global user.name “John doe”
git config–global user.email jdoe@example.com
git config –list
4. git status
5. git add -A
6. git commit -m “comment”
7. git remote add “repo name” [url]
8. git push –set-upstream origin main
ssh-keygen. This utility is used to generated public-private key pair; 2 files each. Private key file is goes stored to Windowsuser.ssh. Public key be stored on your github account settings. Now you can git push to your github repo securely.
Branching: This is where you enhance, fix defects, develop new user story(s). Each one to have new branch. How to achieve it? Begin on your main branch.
git branch [new branch_name]; new branch is created from your original branch
git branch -d [branch you want to delete]
Switch branches
git checkout [branch name you want to switch to]
git pull origin
git pull does gets the latest to branch from origin; conflicts may occur, if you have modified locally; other developer pushed to origin the same file(s).
git log
You are working on a branch. So with some changes it is in draft on your branch. You are suggested to take latest say from master. Park your draft changes to Stash; temporarily until you decide it is good/unstash it or discard it. git pull origin master. Note: Multiple stashes are possible on your branch.
git log
Stash
git stash apply; applies most recent stash{0} and yet keeps that stash
git stash list; lists all stashes with index 0…up; that were stashed from various branches
git stash show stash@{0}
git stash drop
git stash pop; discards most recent stash
git stash clear; all stashes are discarded
Diff
git diff; shows differences of files that are compared to staged ones.
Submit your review | |
Helpful steps