How to Install and Configure Git and GitHub on Mac / MacOS (2024)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how you can install and configure git and GitHub on your Mac operating system so let's get started and let's see how we can do it so first of all we will start with the installation of git so for that just open your favorite browser and search for git and the first link which will appear here will be from giyen cm.com so we are going to click on this link and here you will be able to see this download from Mac option so just click on this download from Mac button now on this page you will be able to see different ways using which you can install git on your Mac operating system the first way is by using Brew brew is a package manager and it allows you to install various different packages on your Mac operating system so if you want to use Brew you can use Brew install git similarly there is a tool called Mac ports and using that you can uh install git by using this command which is Pudo Port install git but my favorite way of installing git on my Mac operating system is this Third Way which says which says Apple ships a binary package of git with xcode so xod code is a tool which you can download and install from your app store and it allows you to develop in various different languages on your Mac operating system so if you are a developer any way you will be downloading the a code on your Mac operating system for various different purposes and one of those purpose is to install the version of git also so that's why I like this third way so let let me show you how you can install the xcode so first of all you need to open the app store you can find the App Store icon on the doc this is the App Store icon so just click on that or you can also search for App Store in your Launchpad and then click on that and App Store will start from here just search for xcode and then press enter which is going to search for xcode and the result which we are uh looking for is this one which is called xcode developer tools here I'm going to click on this uh download button so in my case it shows this warning which ISS download the older version of xcode the current version requires Mac OS 13.5 or later but you can download the last compatible version because right now if I click on the Apple logo and then click on about uh this Mac I have the 13 version not the 13.5 so I can uh download the older version if you have the latest version of Mac OS uh you can download the latest version of uh compatible xcode here I'm going to click on download button which is going to start the download of the xcode so you can see uh this download has been started it's around 7 GB uh of download so it will take some time for the download to complete you can also go to the Launchpad and see the download process here you can see this download is going on so it's going to download around 7 7 GB of uh data so it will take some time so just wait for the download to finish so once the download is complete it's going to start the installation process as you can see when I hover over this circle installation process is about 2% complete so now the xcode is installed on my Mac operating system once it's installed you will be able to see open button in front of xcode also in the Launchpad you will be able to see this xcode icon so I'm going to click on this xcode icon let me minimize this app store and then it's going to start the X code so once you have installed xcode on your Mac operating system let's open our terminal and let's see the version of git so I'm going to click on this uh Spotlight search option and then I'm going to search for the terminals and then just click on the terminal option which is going to open the terminal for you here to check the version of git you just need to write git space hyphen hyphen version and then press enter and it's going to show you the version of git you have in my case it's Git Version 2392 two at the time of making this video and you can see in the brackets I can also see apple git 143 so because we have installed git using the xcode it shows us this apple git hyphen 143 so git is now working on our Mac operating system now let's create a git repository and then commit the code and then let's try to push that code to the GitHub repository so I already have a python script and uh I want to push that code in a git repository so I'm going to go to my finder I'm going to right click on the finder and then open the documents folder where my uh sample project is there this is the folder which I want to push to the GitHub repository so I'm going to go inside this folder now as you can see the location of this folder is users forward SL codeb SL documents slash samples folder so so I need to navigate to this directory in my terminal also if you want to see the location you can also see the location by just right clicking on the file and then when you select the get info you will be able to see the path of this file here so you can see users then code bind documents and then sample so from here also you can copy the path name right click here and then click on copy as path name and then you can CD into that directory so let me clear the terminal first and let's start from the beginning so I'm going to CD into the directory where my project is present as I have copied the path I'm going to just command paste here and this is the path of my python project so I'm going to just press enter and now I'm currently in the sample project in my Mac operating system right in the sample project I have this python script which is test.py when I do LS here you will be able to see the same file here so let me just uh resize this and then open this uh sample folder on the right hand side now before starting with the initialization of git and committing our uh files let's also create a GitHub repository for this project so as I said my uh python script resides in the sample uh directory and that is the name I want to give to my GitHub repository also so once again I'm going to go to my favorite browser and then I'm going to search for GitHub and the first link which will appear here will be from github.com so we are going to click on this link here this is the main page of uh GitHub you can sign in to your GitHub by clicking on the signin button if you don't have uh any account you can click on sign up and then provide your email ID and password and then your GitHub account will be created and once you are signed in to your GitHub account it looks like this so here we need to create a new Repository you can create a new repository by clicking on this green new button or you also have this plus button at the top and you can click on the new repository option from here also so I'm going to click on this plus button and then click on new repository which is going to start process of creation of new repository now as I said I want to name my repository as sample right so so I generally like to give the same name to my repositories as my local project name in my case it's sample but in your case it can be anything right so in whatever project directory your code resides just choose the same name as your repository name so here I'm going to name my repository as sample here I can uh write the small description for example python project and then I can choose which type of repository I want generally people choose public repository which is visible for everybody on GitHub if you want to choose the private repository you can only create a selected number of private repository using git with your free account so I'm going to choose the public option here you can also initialize the readme file readme file is the file which gives information about your project you can check this checkbox to create a readme file for now I don't want to create it so I'm going to leave it as unchecked also you can add the git ignore to your project and license file to the project for now I'm going to leave them as none so it's not going to create any of these files I just want to create a repository here so I'm going to click on the create repository option which is going to create my repository once my repository is created you can see the name of the repository in the URL so github.com slm my username which is p knowledge for/ the name of the repository here also you can see uh my GitHub username which is p knowledge and inside the P knowledge account I have this sample repository now once your repository is created GitHub is going to show you the hints how you can uh create or initialize a git repository how you can add files how you can commit files so you can see you have uh three options here you can clone this repository right so what it's going to do is it's going to clone this repository locally if you already have your project Loc locally then you will use the second option which is create a new repository on the command line and then we are going to P our code so we will use the second option here right so let's uh do that let me open the command terminal and let me move it to the right hand side because we are going to use the same kind of commands right so if you want to create a read me file you can use the First Command so I'm going to just copy this Echo command and then paste it into the terminal what this does is it's basically going to Echo this hash space sample text into the readme file so it's going to create a readme file and then put hash space sample uh text into the readme file I'm going to press enter and then when I give the ls command now I can see that I have uh two files here one was my test.py file and I also have one more file which is readme.md file which I have created if I want to see the content of readme I can do cat readme.md and you can see we have just uh added this hash sample in the readme file now in order to initialize a git repository in your uh project locally just write git in it and this is our second command this is going to initialize a git repository in your project so I'm going to press enter here and it says initialized empty git repository in your sample folder It also says that uh it has created this dogit folder inside your sample directory now when you do LS you will not see dogit uh directory here for that you need to write LS space hyphen Al and then press enter and then you will be able to see this dogit directory in the result that means this dogit directory is a hidden file now the third command it says is you need to give the git add and the file name so you need to add your files into the git system but before that you can also give this command which is git status command and it's going to show you this kind of output right so it says untagged files and it says I have three untracked files one is this DS store which is a hidden file which I don't care about second one is the readme file and third one is the test.py file both are in red let me just remove this uh dot uh DS store because I don't need this file so I'm going to to write RM hyphen RF and then the name of the file which is DS store which is going to remove this file and then let me give the git status uh command once again and now I have these two files which are untracked and it's shown in the red color right that means our files are present here but we haven't added those files into the git system so to add those files into the git system you give these commands write get add and the name of the file in our case we need to add two files one is the readme.md file and other is the test.py file so we can write get add and then you can just write the name of the readme file and then you can write the name of the test.py file so either you can do this the easy way of adding the file into your the git system is you just need to write git add space dot which means it's going to add all the untagged file into the git system press enter and then the files are added to git me move it little bit up so that you will be able to see it properly we are going to give this git status command once again you can switch between these commands if you have already given some commands previously you can press up key in your keyboard and it's going to give you uh those commands once again so I'm going to write get status here once again and now I can see the status of these files are these are added to my git system and now they are green but it says changes to be committed so we have added our files to G system but they are still uncommitted we need to commit them right so this is where we use the third command which is get commit then space hyphen M hyphen is the flag you use to provide any comment to your commit so here I'm going to just write uh first commit so this will be the comment for your commit you provide these kind of comments to know what you have committed so just the information about the commit when when you give this command you don't need to give the file names after that when you give this command all the uncommitted files will be committed in our case readme and test.py files will be committed so press enter and you can see both the files are committed now we need to switch to the main branch of our git so this is the next command we need to give here which is git Branch space hyphen M and then branch name generally the default Branch name in git is main right so I'm going to just write git Branch space hyphen capital m not the small M and then the main right so it's going to switch to the main branch I'm going to press enter and now we are in the main branch now in order to find out or show the list of all the branches which are present in your git repository you can simply give this command which is git branch and then press enter it's going to show you all the branches present on your project we have just created only one branch which is the main branch and this estx in front of it is going to show you which branch is the active Branch right so now we have switched to the main branch now everything we have done till now we have done it locally when we have given this uh get commit command you can also see the username and the email ID and it says the name and the email address were configured automatically based on your username and host name right if you want to give the custom username like in my case let's say I want to give the custom username P knowledge to the git uh configuration and then I want to give the custom email ID then what you need to do here is and I will recommend these two steps for you so before uh pushing your code to the GitHub repository just run these two commands which is git space config then write user dotame and then your username so whatever username you want to provide here you can provide uh your username for your uh git repository or git configuration I'm going to provide knowledge as the username here and then press enter and it's going to set this name as my git username for my git config then I'm going to uh also assign the email ID so for that you need to write get config space hyphen hyen Global and instead of user.name you need to write user. email and then then the email ID I'm going to give any random email ID for now for example XYZ at theate gmail.com but you might want to give the proper email ID here okay and then I'm going to press enter and what these two command are going to do is it's going to uh set the profer username into the git config and it's going to set the proper email ID in your git config now in order to view your config you can write this command which is git config and then if you want to see the systemwide config just write hyphen hyphen system spacee hyphen hyphen list and then press enter right now I don't have any system uh wide config let's do it like this for example get for config space hyphen hyphen list and it's going to show you you the user config for you okay and you can see the default branch is main the default username is p knowledge which we have set the default email is this one which we have set and then all the other configurations are listed here so everything looks good to me now I have cleared this terminal so that we can see uh the next commands so next command here is git remote ad origin and then the URL now I will recommend you to not to use this command because when you use this command and the next command the error will appear on your terminal which will say that the method you are using is already expired let me show you how you can properly run the command instead of these command you need to run other commands which are similar to these commands but you need to to change the commands first you need to create your personal access token and then you will be able to uh create those commands so for that what you need to do is let me just uh copy this uh URL and paste it into the new uh Tab and then I'm going to uh open my GitHub account and here you need to click on your profile and then select settings here go to the settings on the left hand side just scroll down at the very bottom and then click on developer settings and here you need to create a new personal token so I'm going to click on personal access token here and then click on token classic once you click on token classic you will see this section just click on generate new token and then click on generate new token classic which is going to create a token for you now you can name your token anything for example I'm going to name my token as sample token here and then you can also decide uh when it's going to expire in your case you might want to use uh no expiration if you don't want your token to expire or you can give a longer uh period for your token example if you want to give any custom expiration you can uh give the custom expiration here also for now I'm going to just uh give the 7 days because uh I want this token to be expired because I'm going to uh create this token and you guys will be able to see this token so anyway it will not be um good idea to keep this token forever but in your case just choose the longer date here now in the select scope just uh check on every check box if you want to give all all the Privileges to this token so I'm going to check each and every check box from here and once you have checked all these check boxes click on generate token which is going to generate the token for you now keep in mind you can only see this token once so you need to copy this token and then save it somewhere where you will be able to access it once again you can see make sure to copy your personal token you won't be able to see it again so let me open the text addit for example and there I want to just paste it for now so that I will be able to use it later copy the command command will be the same you just need to add this URL token in front of this GitHub so I'm going to just copy this URL token and after https colon for/ slash just paste your token and then provide at the rate option so just write uh add the rate and then github.com and then leave your username and leave your password right so basically the format of this command will be like this so get remote add origin https colon sl/ your token name at theate github.com which is here for slash your username in my case it's p knowledge and then your repository name in my case it's sample right so this username and the repository name you will be able to see in your GitHub so you can see this is the username this is the uh repository name you can also see username and repository name here in the command right so this will be the command I'm going to just copy this command once again and then paste it into the terminal make sure you are running your commands in the same folder as your repository right I'm running all these command in the sample project right and now the remote origin is added and now we can run the next command which is the last command which is get push space hyphen U origin main so let me just uh copy this command and then press this command and hopefully you will not see any error you can see we have pushed successfully our code to the main branch and that means when you go to your GitHub repository and when you refresh this page where you have created your GitHub repository you will be able to see your code files you can see in my case it's readme.md which have uh this sample uh text here and then I have this test.py file which have my python script content here okay now let's say I want to change uh some uh something in my python script I'm going to do LS and then I'm going to open this python script using any editor let's say I want to open this uh python script uh using idle or Visual Studio code or you can use any Editor to change the text for this right let's say I'm going to use Visual Studio code to change this python script here I also want to add print uh hello world here okay and then save my code once I have changed my script that means I have uh some uncommitted code now so I have added some more code into the file and then when I uh do get status into the same folder so status and then press enter it says this file is modified right so once again I need to commit this file so I can write get commit and then hyphen M and then the name let's say second commit here and then you can just give the file name which is test.py in my case right and then press enter and this file is committed once the file is committed you can push your changes once again by using this command or you have already used this command so just use uh the top Arrow key and then give this command which is G push space hyphen u space origin space main which is going to push your changes once again and once the changes are pushed once again refresh your code so you can see I have added print uh statement here on the third line but right now I don't see it because I need to refresh my repository so let me refresh it and now I can see this print statement here right so this is how you can uh once again commit your changes and push your changes so this is how you can install git and configure GitHub on your Mac operating system I hope you've enjoyed this video and I will see you in the next video
Info
Channel: ProgrammingKnowledge
Views: 6,984
Rating: undefined out of 5
Keywords: How to setup Git and GitHub on Mac?, How to install Git on Mac osx?, How to use Git in Windows?, What is the latest version of Git for Mac?, How to use GitHub on Mac?, How do I install and configure Git and GitHub on Windows?, How to configure GitHub in terminal Mac?, How do I open GitHub in Mac terminal?, Is GitHub available on Mac?, M1, M2, M3, MacBook Pro, MacBook Air, Mac, MacOS
Id: p0Js7IF17yI
Channel Id: undefined
Length: 29min 13sec (1753 seconds)
Published: Thu Jan 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.