{"id":508,"date":"2021-03-23T21:34:23","date_gmt":"2021-03-24T02:34:23","guid":{"rendered":"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/?p=508"},"modified":"2022-04-25T09:46:58","modified_gmt":"2022-04-25T14:46:58","slug":"learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners","status":"publish","type":"post","link":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/","title":{"rendered":"Learn How to Use Version Control with Git and GitHub: The Absolute Guide for Beginners"},"content":{"rendered":"\n<p>If you are new to programming, version control is one of the first concepts you must learn, but what does version control mean?<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#What_is_Version_Control\" >What is Version Control?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#What_are_the_benefits\" >What are the benefits?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Version_Control_Hosting_Platforms\" >Version Control Hosting Platforms<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Public_vs_Private\" >Public vs Private<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Lets_Learn_Version_Control_with_Git\" >Let\u2019s Learn Version Control with Git<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Prefer_to_watch_the_video\" >Prefer to watch the video?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Configuring_your_Identity\" >Configuring your Identity<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Initialize_a_repository\" >Initialize a repository<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Make_your_first_commit\" >Make your first commit<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#%E2%80%8DTime_to_Save_My_Local_Repo_in_Github\" >\u200dTime to Save My Local Repo in Github<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#%E2%80%8DPush_it_to_Github\" >\u200dPush it to Github<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#HELP\" >HELP!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Cloning_a_Repository\" >Cloning a Repository<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#%E2%80%8DDont_push_confidential_files_to_Github\" >\u200dDon\u2019t push confidential files to Github!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#%E2%80%8DPieces_of_Advice\" >\u200dPieces of Advice<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Commit_as_many_times_you_can\" >Commit as many times you can!<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Pull_before_pushing\" >Pull before pushing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/#Work_on_independent_branches_then_merge_to_main_branch\" >Work on independent branches, then merge to main branch<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Version_Control\"><\/span>What is Version Control?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can find multiple definitions in the web that can be too technical. However, I will put this in simple words: Version control allows you to track any changes of made on a project, such as every time you made a change on a file, which lines\/words\/letters were changed on that file, who made the change on the file, or when the person made that change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_the_benefits\"><\/span>What are the benefits?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Trace all the changes made<\/strong>: Although this is pretty much the definition of version control, it is useful when you need to check at what point in the process things got changed.<\/li><li><strong>Multiple programmers working on multiple features<\/strong>: You will notice this when working with teams, but essentially while you are working on feature A, another programmer can be working on feature B, without waiting for each other to complete their respective feature development.<\/li><li><strong>Fast development<\/strong>: Since multiple programmers can be working at the same time on several features of a project, the development speed increases; hence your team, unless you are a solo-team is able launch a product is less time.<\/li><li><strong>Room to make mistakes<\/strong>: Have you heard about software having v1, v1.1, v1.2, v2, v2.3\u2026? Well, if you introduce a new functionality for a new version in a project and let\u2019s say it is a disaster with too many bugs, you can always go back at any point a use the latest working version of a project.<\/li><\/ul>\n\n\n\n<p>There are different version control options available out there such as Git, Mercurial, Monotone, and many others that I\u2019ve never heard of, and probably you too unless it is a used for a specific case. There are different varieties of version control: centralized and distributed. &nbsp;If you are interested in reading more about centralized vs distributed version controls in <a href=\"https:\/\/medium.com\/faun\/centralized-vs-distributed-version-control-systems-a135091299f0\" target=\"_blank\" rel=\"noopener\">this article<\/a>.<\/p>\n\n\n\n<p>However, if you don\u2019t know which version control to learn, then learn Git. It the most popular out there and most of the companies use it.<\/p>\n\n\n\n<p><strong>Note<\/strong>: Git is a distributed version control system. For more information about Git, checkout their website https:\/\/git-scm.com\/<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Version_Control_Hosting_Platforms\"><\/span>Version Control Hosting Platforms<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are many hosting platforms out there such as <a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noopener\">Github<\/a>, <a href=\"https:\/\/bitbucket.org\/\" target=\"_blank\" rel=\"noopener\">Bitbucket<\/a>, or <a href=\"https:\/\/about.gitlab.com\/\" target=\"_blank\" rel=\"noopener\">GitLab <\/a>that allows you to store your projects for free. This is important because you can keep you code on the cloud, instead of in your local machine and you will be able to \u201c<em>clone<\/em>\u201d or copy it or access it from anywhere in the world.<\/p>\n\n\n\n<p>It also serves as the hub for teams to contribute to a project or adding their chunks of code symbolizing the development of a feature or fixes of a project.<\/p>\n\n\n\n<p>Learning any version control hosting platform is more than sufficient, as the concepts are generally similar in any of them. The most popular and widely used is Github.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Public_vs_Private\"><\/span>Public vs Private<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Although it sounds self-explanatory, it doesn\u2019t hurt to mention you can keep your repositories on any of these version control hosting platforms as public or private.<\/p>\n\n\n\n<p>Why would you keep a repository public?<\/p>\n\n\n\n<p>There are several reasons, you want to show off the code of a project or share it with other developers. Usually, when you are looking for a job having some public repositories is good for potential employers to checkout your code and the quality of it. You can tell a lot by checking a programmer\u2019s coding style.<\/p>\n\n\n\n<p>However, you don\u2019t always want to make those repositories public unless you want to show the code base of a product you are monetizing and want others to see it and copy it, which is a big no no.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Lets_Learn_Version_Control_with_Git\"><\/span>Let\u2019s Learn Version Control with Git<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The first thing you are going to do if you haven\u2019t is to <a href=\"https:\/\/git-scm.com\/downloads\" target=\"_blank\" rel=\"noopener\">download Git<\/a> on your local machine. Feel free to use the default installation instructions unless you have experience working with Git.<\/p>\n\n\n\n<p>Once it is installed, we are going to open the terminal and setup some basic configuration. &nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prefer_to_watch_the_video\"><\/span>Prefer to watch the video?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Beginner&#039;s Tutorial: Learn Version Control with Git and GitHub\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/liBCBJiLhA0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Configuring_your_Identity\"><\/span>Configuring your Identity<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The first thing we need to do is to set up your user name and user email. This information is used at the moment of committing changes to allow you to track who made the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git config --global user.name \"Andres Reales\"\ngit config --global user.email myemail@example.com<\/code><\/pre>\n\n\n\n<p>If you need to verify if these values were set correctly, you list the information using the following command<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git config --global  --list<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Initialize_a_repository\"><\/span>Initialize a repository<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Time to start our first ever git repository. If you have a website, an app, or you are simply starting from scratch and you want to start your repository make sure you go to your project\u2019s folder using the terminal<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>cd go\/to\/my\/project\/folder<\/code><\/pre>\n\n\n\n<p>Once you do that, we are going to initialize our repository with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git init<\/code><\/pre>\n\n\n\n<p>A hidden folder called .git is created in your project\u2019s folder. If you want to check it, you can run the following:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>ls -a    \/\/ if you are using bash or a linux terminal\ndir \/a:hd  \/\/ if you are using the windows command terminal<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Make_your_first_commit\"><\/span>Make your first commit<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>It\u2019s time to do our first commit, or in other words, telling git we want to generate a new version of the changes we made in our project\u2019s folder. If you are starting you could add a README file or basic index.html file to your project\u2019s folder.\u200d<\/p>\n\n\n\n<p>Take into account that any time you create, update or delete a file in your project, git will detect it. In order to check what changes we made we use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git status<\/code><\/pre>\n\n\n\n<p>You should see the updates or untracked files in your project. In my case, it is showing that the index.html file is untracked.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"147\" src=\"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-1.png\" alt=\"Learn Version Control with Git 1\" class=\"wp-image-515\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-1.png 618w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-1-300x71.png 300w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><figcaption>Git Version Control &#8211; Untracked files<\/figcaption><\/figure><\/div>\n\n\n\n<p>Since we need to track changes in our project we are going to stage the files we want to commit.<\/p>\n\n\n\n<p>\u200d<strong>Note<\/strong>: Staging in Git is a way to tell the version control system that there are certain files are going to be part of your next commit. In other words, let\u2019s create a new version of the changes we made of certain files.<\/p>\n\n\n\n<p>\u200dIn order to stage my index.html file, I will use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git add index.html<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: If you have multiple files you want to stage and you want to avoid staging a file at a time, you can run the following command instead:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git add .<\/code><\/pre>\n\n\n\n<p>Once you stage your files, you should notice a green color output showing the staged files.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"402\" height=\"77\" src=\"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-2.png\" alt=\"Learn Version Control with Git 2\" class=\"wp-image-516\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-2.png 402w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-2-300x57.png 300w\" sizes=\"auto, (max-width: 402px) 100vw, 402px\" \/><figcaption>Git Version Control: Staged Files<\/figcaption><\/figure><\/div>\n\n\n\n<p>If by mistake, you staged a file you didn\u2019t want to include in your commit, i.e., a styles.css files, you can unstage it by using the reset command<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git reset styles.css<\/code><\/pre>\n\n\n\n<p>You should see in red color that styles.css has been unstaged.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"124\" src=\"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-3.png\" alt=\"Learn Version Control with Git 3\" class=\"wp-image-511\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-3.png 571w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-3-300x65.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><figcaption>Git Version Control: Staged and Unstaged files<\/figcaption><\/figure><\/div>\n\n\n\n<p><strong>Note<\/strong>: Make sure you add the name of the file you want to unstage, otherwise it will unstage all the files if you use:<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git reset<\/code><\/pre>\n\n\n\n<p>Once you stage all the files you want to track, we are going to commit our changes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git commit -m \u201cInitial commit\u201d<\/code><\/pre>\n\n\n\n<p>Once you do so, it will generate a commit id with files you decided to include.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%80%8DTime_to_Save_My_Local_Repo_in_Github\"><\/span>\u200dTime to Save My Local Repo in Github<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Go to Github and sign up with a new account. Don\u2019t worry, it\u2019s free.<\/p>\n\n\n\n<p>\u200dAfter you create your account we are going to create a new repository.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"359\" height=\"511\" src=\"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-4.png\" alt=\"Learn Version Control with Git 4\" class=\"wp-image-512\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-4.png 359w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-4-211x300.png 211w\" sizes=\"auto, (max-width: 359px) 100vw, 359px\" \/><figcaption>Create a new repository in Github<\/figcaption><\/figure><\/div>\n\n\n\n<p>Fill out the basic information required such as your repository name and the owner of the repository. Make sure you select yourself as the owner!<\/p>\n\n\n\n<p>\u200dYou can also make your repository public if you want anyone on the internet to see your repository.<\/p>\n\n\n\n<p>\u200dOnce that is done, click on next and you will create your repository.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"835\" src=\"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-5.png\" alt=\"Learn Version Control with Git 5\" class=\"wp-image-513\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-5.png 794w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-5-285x300.png 285w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-5-768x808.png 768w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><figcaption>Fill out basic information of your new repository in Github<\/figcaption><\/figure>\n\n\n\n<p>Your repository has been created. You should see the url of your repository. In my case, it is <a href=\"https:\/\/github.com\/arealesramirez\/learningGit.git\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/arealesramirez\/learningGit.git<\/a>. Make sure to copy it as we are going to use it next.<\/p>\n\n\n\n<p>\u200dIt\u2019s time sync your local repository with your Github repository. Open again your terminal and add a \u201cremote\u201d to your local repository.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git remote add origin https:\/\/github.com\/arealesramirez\/learningGit.git<\/code><\/pre>\n\n\n\n<p>Note: If this is the first time you are using Github, the system will prompt you for your Github credentials.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%80%8DPush_it_to_Github\"><\/span>\u200dPush it to Github<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We are going to use the push command to get our index.html file and other files into our Github repository. Since this is the first time you are pushing to your Github repository, we are going to set an upstream or a tracking reference using the option <strong>&#8211;set-uptream<\/strong> or <strong>-u<\/strong> next by the \u201cremote\u201d name and the branch name.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git push -u origin master<\/code><\/pre>\n\n\n\n<p>Go to your repository in Github, in my case l called it learningGit and you will see my local files are now there.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"391\" src=\"http:\/\/box5488.temp.domains\/~becomen3\/staging\/8495\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-6-1024x391.png\" alt=\"Learn Version Control with Git 6\" class=\"wp-image-514\" srcset=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-6-1024x391.png 1024w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-6-300x115.png 300w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-6-768x293.png 768w, https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-content\/uploads\/2021\/03\/Learn-Version-Control-with-Git-6.png 1157w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>My updated GitHub repository after pushing my local changes<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HELP\"><\/span>HELP!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Everyone needs help, so you as well, especially trying to remember all of these new git commands. You can get a description of the commands available using <strong>&#8211;help<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git --help<\/code><\/pre>\n\n\n\n<p>Don\u2019t worry, you will remember these commands easier as you use them more often. In a matter of a time they will be part of your programming knowledge.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Cloning_a_Repository\"><\/span>Cloning a Repository<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Most likely if you are joining a team working on an existing project, you will need to get the project\u2019s code base from the hosting version control. For example, if you were to get my repository called learningGit, you will need to clone it to your local machine.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git clone https:\/\/github.com\/arealesramirez\/learningGit.git<\/code><\/pre>\n\n\n\n<p>And now you will have access to my learningGit repository. This is a public repository, so you can clone it to your local machine to practice the git commands and make any changes to the project locally.<\/p>\n\n\n\n<p>\u200dBased on the project\u2019s settings, you could also push your changes to the hosting platform.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%80%8DDont_push_confidential_files_to_Github\"><\/span>\u200dDon\u2019t push confidential files to Github!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You might have an environment variables file with credentials to connect to the database or API keys from third party platforms. However, you definitely don\u2019t want to include these files to Github or any other hosting version control platform for security reasons.<\/p>\n\n\n\n<p>\u200dTo avoid this we are going to create a .gitignore file (yes include the period before gitignore text) and inside there we are going type the name of the files we do not want to track in our remote version control.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%80%8DPieces_of_Advice\"><\/span>\u200dPieces of Advice<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Commit_as_many_times_you_can\"><\/span>Commit as many times you can!<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Whenever you are working on your projects, make sure to commit and push your changes early and often, even if your code doesn\u2019t work correctly. Trust me, you will want to have something saved instead of nothing if one day your computer breaks and you no longer have access to the code you\u2019ve been working for hours or even days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pull_before_pushing\"><\/span>Pull before pushing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u200dRemember this as you don\u2019t want to mess someone else\u2019s code. You need to pull the latest changes before pushing your changes.<\/p>\n\n\n\n<p>\u200dThink about it, you and Jhon are working on the master branch. Jhon finished developing the contact form before you finished developing the navigation panel. Jhon had already pushed his changes to the master branch in Github repository or wherever the project repository is, but you don\u2019t have those changes yet in your local machine. Once you finish developing the navigation panel, you are exhausted but ready to push those changes to the master branch. If you push your changes without pulling, Jhon\u2019s contact form work will be lost. To avoid this from happening, you will pull first.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git pull<\/code><\/pre>\n\n\n\n<p>In that way, you will get the latest changes including Jhon\u2019s contact form. Now it\u2019s time for you to push your changes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git push<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Work_on_independent_branches_then_merge_to_main_branch\"><\/span>Work on independent branches, then merge to main branch<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If we go back to the previous example, Jhon is working on the contact form and you are working on the navigation panel. These are two different functionalities or tasks. Generally, it is better to have a working branch where you have a working version of your project.<\/p>\n\n\n\n<p>\u200dIt\u2019s time for you start working on the navigation panel, right?<\/p>\n\n\n\n<p>\u200dLet\u2019s create a new branch, in that branch all the development related to the navigation panel will be done.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git checkout -b navigation-panel<\/code><\/pre>\n\n\n\n<p>You\u2019ve been pushing your changes to the navigation-panel branch, and you completed the development. It\u2019s time to merge all the changes you made on the navigation-panel branch into master branch.<\/p>\n\n\n\n<p>\u200dTo merge the navigation-panel branch into master branch, you need to go to the master branch and pull the latest changes if there are any.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git checkout master\ngit pull<\/code><\/pre>\n\n\n\n<p>Now, merge navigation-panel into master branch and push the latest changes to the remote master branch.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git merge navigation-panel\ngit push<\/code><\/pre>\n\n\n\n<p>Congratulations, you have learned the basic git commands. Go ahead and create new branches, add files, commit changes, push changes, pull changes, change branches, merge branches, etc. The best way to learn is by practicing and practicing. You got this!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are new to programming, version control is one of the first concepts you must learn, but what does version control mean? What is Version Control? You can find multiple definitions in the web that can be too technical. However, I will put this in simple words: Version control allows you to track any &#8230; <a title=\"Learn How to Use Version Control with Git and GitHub: The Absolute Guide for Beginners\" class=\"read-more\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/learn-how-to-use-version-control-with-git-and-github-the-absolute-guide-for-beginners\/\" aria-label=\"More on Learn How to Use Version Control with Git and GitHub: The Absolute Guide for Beginners\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":509,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[28,14],"tags":[],"class_list":["post-508","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git","category-tutorial","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/comments?post=508"}],"version-history":[{"count":2,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/508\/revisions"}],"predecessor-version":[{"id":2526,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/508\/revisions\/2526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media\/509"}],"wp:attachment":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media?parent=508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/categories?post=508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/tags?post=508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}