BASIC OPERATIONS WITH GIT

(Common Git Version-Control Commands)


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]


  1. git clone REPOSITORY-LINK
  2. This command clones or copies your entire remote repository to your local-repository on your computer.
    E.g:-
    git clone https://codeberg.org/Netizenry/get-LBRY.git


  3. git add OPTIONS
  4. This command ADDS the CHANGED/MODIFIED Files/Folders to the Staging-Area in order to be committed.
    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)

  5. git rm OPTIONS
  6. This command REMOVES the CHANGED/MODIFIED Files/Folders from the Staging-Area in order to be obviously NOT committed.
    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)

  7. git commit -m “COMMIT-MESSAGE"
  8. 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.
    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.

  9. git log OPTIONS
  10. Shows all your commits performed on your Local-Repository.
    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)

  11. git push origin BRANCH-NAME
  12. PUSHES or Uploads the COMMITED-CHANGES on your local-repository to a specified branch on your REMOTE-REPOSITORY.
    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")

  13. git pull origin BRANCH-NAME
  14. 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).
    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")

  15. git branch
  16. Shows the names of all the branches created under your Repository (Along with highlighting which branch YOU ARE CURRENTLY ON)
    E.g:-
    git branch


  17. git branch NEW BRANCH-NAME
  18. This command allows you to create a new branch with a name of your choosing.
    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.

  19. git checkout BRANCH-NAME
  20. This command allows you to switch to a specified-branch.
    E.g:-
    git checkout test

    Here; "test" is the name of the branch you are switching to.

  21. git checkout -b NEW BRANCH-NAME
  22. The "-b" OPTION allows you to CREATE & THEN SWITCH to the newly-created Branch.
    E.g:-
    git checkout -b test

    Here; "test" is a new branch that you created & simulataneously switched to.

  23. git status
  24. This command shows the status of your Local-Repository.
    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.

  25. git merge BRANCH-NAME
  26. This command Merges a Specified-Branch (NOT the Branch you're currently on) with the branch that you are currently on.
    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".

  27. git remote OPTIONS
  28. 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.
    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.

  29. git restore FILE-NAME
  30. This command restores your Modified-Files to their previous Un-Modified State. based on the Commit-History recorded on your Local-Repository.
    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.

  31. git fetch
  32. 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 fetch