BONUS: learn git

This exercise shows how to use git which is a program that keeps track of changes I make in a codebase.


requirements

  • I type this in a terminal to make sure git is installed

    git
    
  • If it is not installed on the computer, the terminal is my friend, and shows

    git: command not found
    
    git: The term 'git' is not recognized as a name of a cmdlet,
    function, script file, or executable program.
    Check the spelling of the name, or if a path was included,
    verify that the path is correct and try again.
    

    see how to install git to install git

  • If it is installed on the computer, the terminal is my friend, and shows the manual for git so I know how to use it


how to install git


how to install git on Linux/Windows Subsystem for Linux


Attention

Do this only if you are using Linux or Windows Subsystem for Linux and git is not installed.

Click here if you have MacOS

sudo apt update

I always do a full upgrade (you do not have to)

sudo apt full-upgrade --yes

type this in the terminal to install git

sudo apt install git

Click here to see what directory I am in


how to install git on Windows without Windows Subsystem for Linux


Attention

Do this only if you are using Windows and could not install Windows Subsystem for Linux

Click here if you have MacOS

download and install git

Click on the tab that says no WSL to see the commands or results if you have Windows without Windows Subsystem for Linux

Click here to see what directory I am in


how to install git on Mac OS


Click here to see what directory I am in


how to use Git

git help
git help --all
q
git help --guides
git help attributes
q
git help everyday
q
git help glossary
q
git help ignore
q
git help modules
q
git help revisions
q
git help tutorial
q
git help workflows
q
git help init
q
git init --help
q
git help add
q
git add --help
q
git help commit
q
git commit --help
q
git help status
q
git status --help
clear

how to create a new repository

PROJECTNAME is the name of the project you can use any name you want

go back to the terminal

PROJECTNAME=project_name
mkdir $PROJECTNAME && cd $PROJECTNAME
echo "# $PROJECTNAME" >> README.md

git init                # mkdir .git and add important files
git status
git diff
git diff --cached
git diff HEAD
git commit --all --message "I cannot commit since I have not told git to track anything yet"
git log
git log --oneline
git log --merges
git log --graph

git add README.md
git commit --all --message "made my first commit"
ls
cd .git
tree
cat description
nano description
$PROJECTNAME; a Git Repository
# hit ctrl+x on the keyboard
Y
cat description
cd ..
clear

git remote add origin git@github.com:$GITHUB_USERNAME/$PROJECTNAME.git

git remote --verbose
git push --set-upstream origin main
clear

how to keep files And folders private

cat .gitignore
ls -a
ls
mkdir DirectoryNotToBeShared
ls
echo "DirectoryNotToBeShared/" >> .gitignore
cat .gitignore
ls -a
touch FileNotToBeShared.extension
echo "FileNotToBeShared.extension" >> .gitignore
cat .gitignore
ls
ls -a
git status
git add .gitignore
git diff
git diff --cached
git diff HEAD
git commit --all --message "created files and directories for git to not track"
git log
git log --oneline
git log --merges
git log --graph
git status
git add DirectoryNotToBeShared/
git add FileNotToBeShared.extension
git status
git push
git status
git log
git log --oneline
git log --merges
git log --graph
clear

# Managing Files and Directories
touch File{1,2,3,N}InThisDirectory.extension
ls
tree
mkdir Directory{1,2,3,N}
ls

tree
touch Directory{1,2,3,N}/File{1,2,3,N}InThisDirectory.extension
ls
tree
touch Directory2/python_file.py
touch Directory2/java_file.java
touch Directory2/java_file.war
touch Directory3/html_file.html
touch Directory3/javscriptFile.js
touch DirectoryN/compressed_file.zip
touch DirectoryN/compressed_file.bz2
touch DirectoryN/compressed_file.xz
touch DirectoryN/tape_archive_file.tar
tree
cd Directory3
pwd
mkdir ChildOfDirectory3
cd ChildOfDirectory3
mkdir ChildOfChildOfDirectory3
cd ChildOfChildOfDirectory3
pwd
touch textfile{1,2,3,N}.txt
ls
tree
cd ../..
pwd
ls
tree
cd ..
ls
tree
clear

how to add files and folders for git to track

tree
git status
nano File1InThisDirectory.extension
I am modifying File1InThisDirectory.extension in $PROJECTNAME
# hit ctrl+x on the keyboard
y
git add File1InThisDirectory.extension
git status
git commit --all --message "I modified File1InThisDirectory.extension in $PROJECTNAME"
git push
git status

nano Directory1/File1InThisDirectory.extension
I am modifying File1InThisDirectory.extension in Directory1
# hit ctrl+x on the keyboard
y
git add Directory1/File1InThisDirectory.extension
git add Directory1/FileNInThisDirectory.extension
git commit --all --message "I modified File1InThisDirectory.extension in Directory1"
git status
git push
git status

git add Directory2/File2InThisDirectory.extension
nano Directory2/File2InThisDirectory.extension
What happens if I modify a file after adding it to tracking?
# hit ctrl+x on the keyboard
y
git commit --all --message "I modified File2InThisDirectory.extension in Directory2"
git status
git add Directory2/File2InThisDirectory.extension
git status
git commit -am "I Modified File2InThisDirectory.extension in Directory2"
git status
git push
git status

nano Directory3/File3InThisDirectory.extension
I Always add after modifying a file and commit
# hit ctrl+x on the keyboard
y
git add Directory3/File3InThisDirectory.extension
git commit --all --message "I modified File3InThisDirectory.extension in Directory3"
git push
git status
git add Directory3/

git status
nano DirectoryN/FileNInThisDirectory.extension
I will ALWAYS BE COMMITTING
# hit ctrl+x on the keyboard
y
git add DirectoryN/FileNInThisDirectory.extension
git commit --all --message "I modified FileNInThisDirectory.extension in DirectoryN"
git push

git status
git add .
git status
tree
git diff
git diff --cached
q
git diff HEAD
q
git commit -am "I added new Ffives to be tracked by git"
git log
q
git log --oneline
git log --graph
q
git commit --amend --message "I Added new Files and Directories in $PROJECTNAME for git to track"
git log
q
git log --oneline
git log --merges
git log --graph
q
git push
git log --oneline
git log --merges
git log --graph
git diff
git status
clear

how to manage branches

git status
git branch
git branch --all
git branch --verbose
git branch -vv
git branch a_new_branch
git branch
git branch --delete a_new_branch
git branch
git branch an_old_branch_name
git branch --all
git branch --move an_old_branch_name a_new_branch_name
git branch --all
git branch --verbose
git branch -vv

git branch a_branch
git branch --all
git checkout a_branch
git branch --all
git status
git checkout main
git status
git branch --all
git checkout a_new_branch_name
git branch --all
git status
git checkout -b a_new_branch
git branch --all
git status
git checkout main
git checkout -b a_dead_branch
git branch --all
git status
git checkout main
git branch --delete --force a_dead_branch
git branch --all
git status
ls
tree

git branch --all
git branch branch1
git branch branch2
git branch branch3
git branch branchN
git branch --all

git push origin a_branch
git branch --all
git push origin a_new_branch
git branch --all
git push origin branch1
git branch --all
git push origin branch2
git branch --all
git push origin branch3
git branch --all
git push origin branchN
git branch --all

how to merge changes

git checkout a_branch
touch file_from_a_branch.extension
mkdir new_directory_from_a_branch
touch new_directory_from_a_branch/File{1,2,3,N}InThisDirectory.extension
git status
git add .
git commit --all --message "I added a new File and Directory in a_branch"
git diff origin/a_branch
git push origin a_branch
git diff
git diff main
git checkout main
git diff origin/main
git diff a_branch
git merge a_branch
git diff
git diff a_branch
git diff origin/main
git status
git push origin main
git status

git checkout -b new_feature
git branch --all
git diff main
git merge main
nano File1InThisDirectory.extension
I had a Genius Idea and tested it in new_feature
# hit ctrl+x on the keyboard
y
git status
git add .
git commit -am "I had a Genius Idea and tested it in new_feature"
git diff main
git diff remotes/origin/new_feature
git push origin new_feature
git checkout main
git merge --no-ff new_feature
I Had a Genius idea, tested it in new_feature and merged it into main
# save and exit
git diff
git diff new_feature
git diff remotes/origin/main
git status
git push origin main
git log
git log --oneline
git log --merges
git log --graph
git branch --delete --force new_feature
clear

how to use tags

git tag
git tag --annotate v0.1 -m "Beta Test version 1"
git tag
git tag --annotate v0.1 -m "Beta Test version 1"
git tag
git tag --annotate v1.1 -m "Version 1.0 revision 1"
git tag
git tag v2.0 --message "Version 2.0"
git tag
git tag vN.M --message "Version N revision M"
git tag
git tag any_tag --message "Description/Comment for the Tag"
git status
clear

git show
git show v0.1
git show v1.1
git show v2.0
git show vN.M
git show any_tag
git show non_existent_tag
clear

git push origin v0.1
git push origin vN.M
git push origin --tags

git log
git log --oneline
git log --merges
git log --graph

review

I ran these commands to keep track of changes in a project


code from the chapter

Do you want to see all the CODE I typed in this chapter?


what is next?

I know

Click Here to see me make a Python Test Driven Development Environment


rate pumping python

If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too.