Create a local git repository and get familiar with some of the essential sub-commands
-
Create a new folder on your file system and name it 'hello-world', then navigate inside
-
Within the 'hello-world' use the right
gitsubcommand to initialize this folder as a git repo -
Create a new file in this folder and name it 'hello-world.txt'. Open this file in VSCode and add some content to it, then save it.
-
Create another file 'my-poem.txt' and write an excepional poem (or not)
-
Use the appropriate
gitsubcommand to 'stage' these newly created files (either individually or all at once)
Remember, use
git statusbetweengitcommands to get a sense of what you just did and whether you andgitare on the same page.
-
Use
git commit -m "<I_AM_GOING_TO_WRITE_MY_OWN_COMMIT_MESSAGE_HERE>"to commit your staged changes. -
Use
git logto confirm your commit was recorded -
Create some more changes (any you want, new files or changing existing ones,
gitonly cares that there are changes) and make another commit. Confirm again withgit log
-
Use the appropriate command to create (and checkout) a new branch off of main called
experiment -
Make some more changes in this branch and commit them. Try to make at least 2 new commits in this branch.
-
Use
git logto confirm the history of this branch
-
Use the right command to checkout
mainagain. Usegit logto confirm it doesn't contain any of the work on theexperimentbranch -
Use the right command to merge the changes from
experimentintomain. Remember, thegit merge <branch>command merges the changes from<branch>into the branch you are currently on, so make sure you are onmainfirst! -
Use
git logto confirm all the changes have been integrated into the current branch -
BONUS: if you got this far, try using the below version of
git logto see a commit history view that helps with visualizing branching:
git log --oneline --graphUltimately Github will be the preferable tool for tracking such changes visually, but it's good to know a primitive version of this exists right within git.
Some important commands we learnt so far include:
-
git init- make a new local repo -
git status- get feedback on the current state of your repo -
git add <filename>- add a specific file to git for staging -
git add .- add files to git for staging -
git commit -m '<message>'- commit staged files as a discrete unit of 'work' that git tracks -
git log- print the commit history -
git checkout -b <branchname>- create a new branch with the given name -
git checkout <branchname>- switch to the branch with the given name -
git merge <branchname>- merge the latest changes from the branch with the given name into the branch you are currently on