{"id":848,"date":"2024-12-15T12:26:20","date_gmt":"2024-12-15T09:26:20","guid":{"rendered":"https:\/\/itgen.itbumper.com\/?page_id=848"},"modified":"2024-12-15T12:26:21","modified_gmt":"2024-12-15T09:26:21","slug":"0091_git-advanced","status":"publish","type":"page","link":"https:\/\/itgen.itbumper.com\/?page_id=848","title":{"rendered":"0091_GIT: Advanced"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSome transcription My_program v 2.41.2\n                                |  | |\n                                |  | Patch\n                                |  |\n                                | Minor\n                              Major\n                                   \nGiven a version number MAJOR.MINOR.PATCH, increment the:\n    MAJOR version when you make incompatible API changes;\n    MINOR version when you add functionality in a backward compatible manner;\n    PATCH version when you make backward compatible bug fixes;\nAdditional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.\nMore information --&gt; https:\/\/semver.org\/\n\nInstallation\n    -Windows\n        1. Download https:\/\/git-scm.com\/download\/win\n        or use PowerShell:\n             winget install --id Git.Git -e --source winget\n        2. Install by default\n        3. Check version\n            in Git Bash console: git --version      \/ if you can see the version - Ok\/\n                                 git --help         \/ will provide you more information \/\n\n\n        You have an option:\n                    -use Git Bash console\n                    -use Terminal in Visual Studio Code (ctrl + ~)\n                        *Anyway you have to use Linux commands like cd,ll, mkdir, etc\n\n        4. Create a folder for your repository using cd, mkdir, etc. You may use windows explorer as well\n                Example:\n                    cd \/d\/Install\/GIT\n                    mkdir my_way; cd my_way            \n        5. Initialisation the repository\n                    git init        \/ Inside the folder my_way will be created the hidden folder .git \/\n\n        6. We have to set a username and email\n                Example:\n                    git config --global &quot;Radik Makhmudov&quot;\n                    git config --global Radik.M@itbumper.com\n                    git config --list \/ check global configuration \/\n\n        7. Start using\n\n        The levels \n            1. Working directory\n                -create a folder \n                -create a file and edit\n                The first state of new folders and files are &quot;Untracked&quot;  \/ Folders - green dot, files marked &quot;U&quot; in file explorer&quot; \/   \n                Example:\n                    mkdir GIT; cd GIT\n                    touch a0001_git\n                    git status  \/shows the current branch name, untracked files and folders \/\n                        $ On branch main\n                        Your branch is up to date with 'origin\/main'.\n                        Untracked files:\n                        (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)\n                        GIT\/\n                        nothing added to commit but untracked files present (use &quot;git add&quot; to track)\n                \n            2. Staging area (index)  \/files and folders --&gt; .git\/objects\n                    Example:\n                    git add GIT\/    # We gonna add the whole directory named GIT\n                    git status\n                        $ On branch main\n                        Your branch is up to date with 'origin\/main'.\n                        Changes to be committed:\n                        (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)\n                        new file:   GIT\/a0001_git\n                    Files marked &quot;A&quot; (Added) in file explorer\n                    to add * folders and files use git add .\n\n                Tracking status:\n                  -untracked    \/marks files and directories not added in the index yet\n                  -unmodified   \/added and commited files have no changes\n                  -modified     \/commited files have changes since last commit\n                  -staged       \/marked a modified file in its current version to go into your next commit snapshot\n\n\n                If file was changed then\n                    git status\n                        $ On branch main\n                        Your branch is up to date with 'origin\/main'.\n                        Changes to be committed:\n                        (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)\n                        new file:   GIT\/a0001_git\n                        Changes not staged for commit:\n                        (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)\n                        (use &quot;git restore &lt;file&gt;...&quot; to discard changes in working directory)\n                        modified:   GIT\/a0001_git\n                    Files marked &quot;M&quot; (Modifided) in file explorer\n                    then do\n                    git add \/GIT or git add GIT\/a0001_git   \/ status will change: &quot;M&quot; will become &quot;A&quot; \/\n           \n            3. Repository   \/ files and folders --&gt; .git\/objects \/\n                Example:\n                    git commit -m &quot;07\/22\/2023&quot;      \n                        $ git commit -m &quot;07\/22\/2023&quot;\n                        &#x5B;main 436824f] 07\/22\/2023\n                        1 file changed, 89 insertions(+)\n                        create mode 100644 GIT\/a0001_git\n\n        How to:\n            Excluding files\n                Just add the file or folder name in the file .gitignore\n                Example:\n                    I created the file &quot;dont_want_to_track&quot; \/ Status: Untracked files --&gt;only &quot;dont_want_to_track&quot;\n                    In root directory create a file .gitignore, then add the filename &quot;dont_want_to_track&quot; in it. \/ Status: Untracked files--&gt; only &quot;.gitignore&quot;\n                    *If you want to exclude a folder then add \/folder in the .gitignore\n                    then do\n                    git add .\n                    git status   \/ --&gt;new file:   .gitignore, the file &quot;dont_want_to_track&quot; doesn`t show anymore \/\n            \n            Figure out in which branch you work\n                Remember. There are two types of branches: local and remote. In the VSC, have a look at the left bottom corner (GIT label)\n                Examples:\n                    git branche     \/ shows current local branche \/\n                    $ git branch\n                    * main\n\n                    git branche - a \/ shows all current and remote branches \/\n                    $ git branch -a\n                    * main\n                      remotes\/origin\/main\n\n            Create a new branch\n                Two ways to create a new branche: using terminal and an APP. In the VSC, use tools hidden at the left bottom corner (GIT label)\n                Example:\n                    git branch New_Branch\n                    git branch\n                    $ git branch \n                     New_Branch     \/ just created branch \/\n                    * main          \/ * -means currently chosen branch \/ \n                If you want create a new branch and make it the current use this command:\n                git checkout -b New_Branch\n                Two ways to create a new branche: using terminal and an APP. In the VSC, use tools hidden at the left bottom corner (GIT label)\n\n            To rename the current branch use: git branch -m new_branch_name\n\n            Delete some branch\n                Example:\n                    git branch -D New_Branch\n                    $ git branch -D New_Branch\n                    Deleted branch New_Branch (was 3d3bc2d).\n                Before deleting the branch, you have to set on to another branch. You can`t remove the current branch.\n            Select branch\n                Two ways to create a new branche: using terminal and an APP. In the VSC, use tools hidden at the left bottom corner (GIT label)\n                Be aware. If you have modified files, decide in which branch you will commit to the current state.\n                Example:\n                    git checkout new_branch\n                    $ git checkout new_branch\n                    Switched to branch 'new_branch'\n                    M       GIT\/a0001_git\n\n                The header is always set on the last commit in the branch. HEAD--&gt;BRANCH--&gt;THE_LAST_COMMIT\n\n            Merge branch\n                When you have completed development in your branch and everything works fine, the final step is merging the branch with the parent (main) branch. This is done with the git merge command.\n                GIT merge basically intergrates your feature branch with all of its commits back to main branch.\n                Be aware. Before doing a merge, you have to be on the main branch.\n                Current branch=Recieving branch\n                Merge branch=Feature branch\n                After the merge, we get a Merging commit. The Merging commit has two parents.\n                Example:\n                git checkout main\n                git branch\n                $ git branch\n                * main              \/ the current branch is main = Ok \/\n                  new_branch\n                git merge new_branch    OR  git merge -m &quot;Merge the new_branch into main&quot; new_branch\n                Merge made by the 'ort' strategy.\n                .gitignore              | 2 +-\n                Bash\/Scripts\/check_raid | 2 ++\n                2 files changed, 3 insertions(+), 1 deletion(-)\n                create mode 100644 Bash\/Scripts\/check_raid\n\n                git log\n                commit 42240c8bc689f25766cdb31b286519988b59b2fa (HEAD -&gt; main)\n                Merge: 7947760 68172ff\n                Author: Radik.M &lt;Radik.M@itbumper.com&gt;\n                Date:   Sun Jul 23 23:48:29 2023 -0700\n\n                Merge branch 'new_branch'\n\n                commit 68172ff47d176d53b1c14177ecdad1d7ba8248f7 (new_branch)\n                Author: Radik.M &lt;Radik.M@itbumper.com&gt;\n                Date:   Sun Jul 23 23:27:15 2023 -0700\n\n                The first commit in the branch new_branch\n\n\n            Clone remote repository\n                git clone &lt;url&gt;  origin     \/ Copy remote repository to your local repository URL=https or ssh \/\n                                            \/ origin is the default name of the remote repository \/\n                                            \n            Add the remote repository\n                git remote add origin &lt;url&gt;\n                                            \/ origin is the name of the remote repository \/\n                After than you have to make a link between local and remote repository \/ \n                git push -u origin &lt;branch&gt;\n                                            \/ origin and branch of the remote repository \/\n                You can use pull and push commands when the sync has been done\n           \n            Send updates from your local to remote repository\n                git push        \/pushes all local changes to the remote branch \/\n\n\n            Download updates from the remote to the local repository\n                git pull       \/ download and apply all changes (updates) from remote branch to the local \/\n\n                git fetch      \/ downloads updates but don`t make changes in the local repository \/\n\n            Get more information about remote repository\n                git remote -v\n                $ git remote -v\n                origin  git@github.com:RadMakGo\/my_way.git (fetch)\n                origin  git@github.com:RadMakGo\/my_way.git (push)\n\n                git remote -vv     \/ shows how the local repository linked with the remote repository \/ \n                $ git remote -vv\n                origin  git@github.com:RadMakGo\/my_way.git (fetch)\n                origin  git@github.com:RadMakGo\/my_way.git (push)\n\n        \n\n            Create a token on the GitHub web site:\n                1. Profile--&gt;Settings--&gt;Developer settings--&gt;Personel access tokens--&gt;Generate new token\n                2. Make a note\n                3. Choose expiration date\n                4. Choose scopes\n                5. Generate token\n\n            Connect your local repository to remote repository\n                1. Be sure that you are in the local repository\n                2. Check that your local repository has no any remote repositories\n                    git remote  \n                3. Go to the github web site and add a repository with the same name (local repository)\n                4. Add the remote repository\n                    git remote add origin https:\/\/github.com\/RadMakGo\/my_way.git\n                5. Rename the remote brache\n                    git branch -M main\n                6. Push the local branch main the remote\n                    git push -u origin main         \/ type username and add token \/\n        \n                Type of objects in GIT: (each object has a unique ID: hash--&gt;sha1)\n                    -blob   \/ file \/\n                    -tree   \/ folder \/\n                    -commit \/ commit \/\n                    -annotated tag  \n\n                The commit refers to the tree\n                Each commit has:\n                    -Author`s name and email address\n                    -Commit`s description\n                    -Parent(s) commit(s)   --&gt;sha1\n                    -Tree                  --&gt;sha1\n\n\n                    $ git log\n                    commit bb65eed885c160dc6dc388dd7c4a42a3aead54fa (HEAD -&gt; main, origin\/main)\n                    Author: Radik.M &lt;Radik.M@itbumper.com&gt;\n                    Date:   Sun Jul 23 23:52:42 2023 -0700\n                    The two first simbols in the hash are &quot;bb&quot; and it means than you can find \n\n                    $ ls .git\/objects\n                                                                                      * \n                    08\/  11\/  2b\/  2f\/  36\/  3d\/  42\/  4c\/  55\/  68\/  77\/  7e\/  83\/  86\/  9e\/  a4\/  af\/  bb\/  c3\/  c8\/  d8\/  e3\/  e5\/  e7\/  f1\/    pack\/\n                    10\/  17\/  2e\/  35\/  3c\/  41\/  43\/  51\/  62\/  75\/  79\/  80\/  85\/  92\/  a0\/  a7\/  b0\/  bc\/  c6\/  d4\/  da\/  e4\/  e6\/  e9\/  info\/\n\n                    ls .git\/objects\/bb\n                    65eed885c160dc6dc388dd7c4a42a3aead54fa\n\n                    in git log commit = folder (bb) + 65eed885c160dc6dc388dd7c4a42a3aead54fa ( ls .git\/objects\/bb )\n\n                    $ git cat-file -t bb65eed         (a small part of the hash)\n                    commit              \/ now we know what the type of object is \/\n\n                    $ git cat-file -p bb65eed\n                    tree 3576c88ef13ee05539aa73009de93edd1a874a0e                    \n                    parent 42240c8bc689f25766cdb31b286519988b59b2fa\n                    author Radik.M &lt;Radik.M@itbumper.com&gt; 1690181562 -0700\n                    committer Radik.M &lt;Radik.M@itbumper.com&gt; 1690181562 -0700\n\n\n                    Now we get some info about the tree\n                    $ git cat-file -p 3576c88e\n                    100644 blob a013ff39131448178649714dbfb00c2f0e562bd8    .gitignore\n                    040000 tree 2ede4efe86dff6185dc90015a77c85944e31edbd    .vscode\n                    040000 tree e3621d92f5b18e88c4c446e4bf327e8cd2f170ed    Bash\n                    040000 tree b0479e5d3b7ad07e3e6e15fb10e5efacb1ce5d6c    GIT\n                    100644 blob e488e34f8e74785aa987e1a42222f64538153ac5    README.md\n\n                    $ git cat-file -p a013ff39\n                    dont_want_to_track\n                    \/logs\n\n\n                    HEAD detached mode\n                    $ git log --&gt; take a needed commit hash\n                    $ git checkout 4e1d039\n                    Note: switching to '4e1d039'.\n                    You are in 'detached HEAD' state. You can look around, make experimental\n                    changes and commit them, and you can discard any commits you make in this\n                    state without impacting any branches by switching back to a branch.\n                    If you want to create a new branch to retain commits you create, you may\n                    do so (now or later) by using -c with the switch command. Example:\n                    git switch -c &lt;new-branch-name&gt;\n                    Or undo this operation with:\n                    git switch -\n                    Turn off this advice by setting config variable advice.detachedHead to false\n                    HEAD is now at 4e1d039 07\/24\/2023\n\n                    Let's find out what the file README.md contents were in that commit.\n\n                    cat README.md\n                    # Things happen, baby; it is a life!\n\n                    # My name is Radik and I've created this repository for a few reasons:\n                    # I want to get new skills and improve existing skills working with tools like VS Code, Git, scripting (Bash), Doker, K8S, Ansible, etc\n                    # The other reason, I want to improve my English skills\n                    # A couple of months ago, my son started to study Python and I hope it will be useful for him too.\n                    # Yeah, sometimes I'll write in the Russian language.\n\n                    Now we retern to the main branch\n                    $ git checkout main \n                    Previous HEAD position was 4e1d039 07\/24\/2023\n                    Switched to branch 'main'\n                    Your branch is up to date with 'origin\/main'.\n\n                    And view again\n                    $ cat README.md \n                    # Things happen, baby; it is a life!\n\n                    # My name is Radik and I've created this repository for a few reasons:\n                    # I want to get new skills and improve existing skills working with tools like VS Code, Git, scripting (Bash), Doker, K8S, Ansible, etc\n                    # The other reason, I want to improve my English skills\n                    # A couple of months ago, my son started to study Python and I hope it will be useful for him too.\n                    # I wish me good luck!\n\n                Change url of the remote repository\n                    git remote set-url origin new.git.url\n                    \n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/848"}],"collection":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=848"}],"version-history":[{"count":1,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/848\/revisions"}],"predecessor-version":[{"id":849,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/848\/revisions\/849"}],"wp:attachment":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}