This is PART-03 of the Yet Another GIT-Reference series.
NOW it’s time for you to learn the bare essentials of all GIT-Commands needed to manage your Sources; [Whether it be Source-Code, Documentations, Websites OR well even a poem]
- git clone REPOSITORY-LINK This command clones or copies your entire remote repository to your local-repository on your computer.
- git add OPTIONS This command ADDS the CHANGED/MODIFIED Files/Folders to the Staging-Area in order to be committed.
- git rm OPTIONS This command REMOVES the CHANGED/MODIFIED Files/Folders from the Staging-Area in order to be obviously NOT committed.
- git commit -m “COMMIT-MESSAGE" This command COMMITS or Transfers the changes/modified-files that were in the Staging-Area to the Local-Repository with a "MESSAGE" that you can convey describing your commits.
- git log OPTIONS Shows all your commits performed on your Local-Repository.
- git push origin BRANCH-NAME PUSHES or Uploads the COMMITED-CHANGES on your local-repository to a specified branch on your REMOTE-REPOSITORY.
- git pull origin BRANCH-NAME PULLS or Downloads the PUSHED-CHANGES on a specified branch on your remote-repository to your LOCAL-REPOSITORY & merges the changes with your local repo (AKA update your Local-Repo in a way).
- git branch Shows the names of all the branches created under your Repository (Along with highlighting which branch YOU ARE CURRENTLY ON)
- git branch NEW BRANCH-NAME This command allows you to create a new branch with a name of your choosing.
- git checkout BRANCH-NAME This command allows you to switch to a specified-branch.
- git checkout -b NEW BRANCH-NAME The "-b" OPTION allows you to CREATE & THEN SWITCH to the newly-created Branch.
- git status This command shows the status of your Local-Repository.
- git merge BRANCH-NAME This command Merges a Specified-Branch (NOT the Branch you're currently on) with the branch that you are currently on.
- git remote OPTIONS This command sets up the connection with your Remote-Repository (AKA "origin") OR shows which Remote-Repository/"Origin" you are connected to.Depending on the OPTIONS Used.
- git restore FILE-NAME This command restores your Modified-Files to their previous Un-Modified State. based on the Commit-History recorded on your Local-Repository.
- git fetch This command retrieves info on all the commits from your remote-repository (from your current branch) in order for you to review them.
E.g:-
git clone https://codeberg.org/Netizenry/get-LBRY.git
E.g:-
git add .
Here we used the period-symbol, which is "." to ADD ALL THE MODIFIED files & folders (If we didn't we would have to specify file or folder names individiually)
E.g:-
git rm -r FOLDER/FILE
Here we used the recursive-option "-r" TO REMOVE ALL THE FILES IN A FOLDERS to prevent it from being tracked by GIT (If we didn't, then we would have to specify file-names individiually)
E.g:-
git commit -m “added new lines”
When you COMMIT the changes to your LOCAL-REPOSITORY, you basically commit ALL the changes that you added to the STAGING-AREA.
E.g:-
git log
OR
git log -p -1
You can also use the "-p" OPTION to get more info & by how many logs (like "-p -1" will give you info in 1 log)
E.g:-
git push origin main
Remember to mention the branch-name while Pushing Changes (It's considered "BEST PRACTICE" to do so; Here the branch-name is "main")
E.g:-
git pull origin main
Just like in case of "git push", Remember to mention the branch-name while Pulling Changes (It's considered "BEST PRACTICE" to do so; Here the branch-name is "main")
E.g:-
git branch
E.g:-
git branch test
Also, in order for the new branches to REGISTER/SHOW-UP in you remote-repository; you should commit & then PUSH while specifying the new branch's name.
E.g:-
git checkout test
Here; "test" is the name of the branch you are switching to.
E.g:-
git checkout -b test
Here; "test" is a new branch that you created & simulataneously switched to.
E.g:-
git status
It which branch you are on, how far BEHIND/AHEAD are you when compared to the MAIN-Branch & Any changes left to be commited.
E.g:-
git merge test
let's assume you're on the branch called "main"; Hence, it will MERGE a branch called "test" with the branch called "main".
E.g:-
git remote -v
OR
git remote set-url
The "-v" OPTION views the URL of Origin; while the "set-url" OPTION sets URL of Origin.
E.g:-
git restore sample.txt
OR
git restore --unstaged sample.txt
Here, "sample.txt" is a Modified-File; Also, if you use the "--unstaged" OPTION then it merely removes the Modified-Files from the STAGING-AREA.
E.g:-
git fetch