explanations
pwd
^ The command pwd
should print the path to your home directory at the moment
by default this is where you usually start when opening a shell
cd /tmp
^ Change directory to /tmp
.
(/tmp is a great place for temporary stuff, careful this place is erased upon reboot)
pwd
^ Prove to me that we changed directories (i.e. it should now print /tmp).
mkdir git2
^ Make a new directory named ‘git2’.
cd git2
^ Change into the git2
directory.
pwd
^ Now displays /tmp/git
.
git init
^ Initialize /tmp/git2
into a git repo.
echo 'my test' >test1
^ Overwrite or make a new file called test1 and makes its contents read ‘my test’.
ls
^ Show me this new file.
cat test1
^ Dumps the contents of the file which should be ‘my test’.
git status
^ Have git tell us of any changes in the current directory.
git add test1
^ Add our new file to the git source code tracking system.
git status
^ Show us that the new file has now been added.
git config --global user.email "[email protected]"
^ This adds your email to your local gitconfig ~/.gitconfig
git config --global user.name "Testy McTesterson"
^ This adds your name to your local gitconfig ~/.gitconfig
git commit -am 'initial add of test1'
^ Make a commit and give it a nice message explaining what is going on.
git log
^ Show us a log of the history of this git repo.
echo 'second test' >>test1
^ Make a second line in our first test file.
git status
^ Show us which files have changed.
echo 'second test file'>test2
^ Make a second test file.
git status
^ Again show us which files have changed.
git diff
^ Show us the changes.
git add .
^ This adds all files and changes present in this directory and all
sub-directories to git source code management tracking system.
git commit -am 'second test'
^ Commit those changes.
git log
^ Show us a log of the history of this git repo.
git checkout -b my_new_branch
^ This creates a new branch and checks that new branch out in a single command.
echo 'second test file but add to the first line'> test2
^ This overwrites that second file with a new first line.
git status
^ This should show us that the second file has changed.
git diff
^ This should show us the differences in the second file that has changed.
git commit -am 'third test'
^ This will commit the differences in the second file that has changed.
git log
^ This will now show the commit where we committed the differences in the second file that has changed.
git checkout master
^ This will now checkout the master branch.
git log
^ This will not show the most recent commit we made because that was in the other branch my_new_branch
because are back on the master branch.
git diff my_new_branch
^ This will show the difference between the master branch and the my_new_branch
branch.
git merge my_new_branch
^ This will merge the differences between the master branch and the my_new_branch
branch.
git log
^ This will now show the most recent commit we just made because we just merged the other branch my_new_branch
into the master branch.
Click the continue button to continue.