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

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"

SYNCHRONIZATION

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

git:~$ git pull

STAGE ALL CHANGES

git:~$ git add -A

UPDATE REMOTE REPOSITORY

git:~$ git branch
 * this checks the current branch being managed
 
git:~$ git add .
 * ALT: git add filename1 filename2

 * add all changed files
 
git:~$ git commit -m "Your commit message here"

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