GIT (CLI)

INSTALLATION

PS C:\> Invoke-WebRequest https://git-scm.com/downloads/win -OutFile .\Downloads\Git-2.49.0-64-bit.exe
PS C:\> .\Git-2.49.0-64-bit.exe
 * ALT: BROWSER > https://git-scm.com/downloads > 

 * Follow guided installation and stick w/ defaults
 
git:~$ git --version
 git version 2.49.0.windows.1

INITIAL CONFIGURATION & INITIALIZATION

Git will start watching the specified directory and will create a hidden folder named ".git" to keep track of changes.

git:~$ git config --list
 ...
 user.email=YOUR-EMAIL
 user.name=YOUR-NAME
git:~$ git config --global user.name {"userName"}
git:~$ git config --global user.email {"emailAddress"}

PS C:\> New-Item -Path {path}\{directoryName} -ItemType Directory
git:~$ cd {directoryName}
git:~$ git init
git:~$ git status
 On branch master
 ...

TRACK HISTORY

//show commit history
git:~$ git log
 commit ... (HEAD -> master)
 Author: ...
 Date: ...

VIEW CHANGES

This is used to review changes made on the remote Github repository prior to modification

git:~$ git fetch
git:~$ git log origin/{branchName}

 * my branch name is "main"

REVIEWING CHANGES

Compare changes between data in current working directory and the last snapshot/commit

git:~$ git diff

 * the "-" represent old version
 * the "+" represent new additions

REMOVING FILES & DIRECTORY

//FORMAT: 
//FILES: git rm {filenameToRemove}
//DIRECTORY: git rm -r {directoryName}

git:~$ git ls-files
 ...
 ...
git:~$ git rm filename


//remove directory
git:~$ git rm -r directoryName

SYNCHRONIZATION

fetch changes from the default remote (origin) and merges them into your current local branch.

git:~$ git pull

STAGE CHANGES

Staging is the process of marking the files to be committed to the repository

git:~$ git add -A
 * ALT: 
    - git add --all
    - git add {filenameWithExtension}

MARK LOCAL CHANGES FOR REMOTE UPDATE

Think of this as git creating a save point.

git comming -m {message}

PUSHING CHANGES TO REMOTE DIRECTORY

git:~$ git branch
 * this checks the current branch being managed

git:~$ git push origin main

RENAMING DIRECTORIES

git:~$ git clone https://github.com/username/repository.git
git:~$ cd repository

 * this cmd clones the directory
 
git:~$ git mv old_directory_name new_directory_name

 * this cmd renames the specified directory
  
git:~$ git commit -m "Renamed directory from old_directory_name to new_directory_name"

 * this cmd commits the changes
 
git:~$ git push origin main

 * this cmd pushes the changes

DELETING FILES

git:~$ cd path/to/your/repository
git:~$ git rm file_name

 * ALT: delete the file from the repository but keep it in the local system
   git rm --cached file_name
   
git:~$ git commit -m "Delete file_name"
git:~$ git push origin main

CREATING DIRECTORIES

git:~$ cd path/to/your/repository
git:~$ mkdir new_directory_name

#stage the changes
git:~$ touch new_directory_name/.gitkeep

 * git doesn't track empty directories. add a placeholder file (.gitkeep) in the new directory to ensure it is tracked

git:~$ git add new_directory_name/.gitkeep
git:~$ git commit -m "Create new_directory_name"
git:~$ git push origin main

Last updated