In today's digital era, Git and GitHub have become essential tools for any developer. Git, a distributed version control system, allows you to manage and keep track of your source code history. GitHub, on the other hand, is a cloud-based hosting service where you can manage Git repositories. This article will guide you through the process of installing Git on a MacBook M1 and uploading your project or files to GitHub.
Installing Git on MacBook M1
To start with, open your preferred browser and search for Homebrew, a package manager that simplifies the installation of software on Apple's macOS operating system. If Homebrew is not installed on your system, copy the command displayed on the Homebrew website and paste it into your terminal. This command will install Homebrew.
Once Homebrew is installed, verify it by typing
brew --version in the terminal. If it displays a version number, Homebrew is successfully installed. With Homebrew now on your system, type
brew install git and hit enter. This command installs Git on your system. To verify if Git is installed, type
git --version. If it shows the Git version, it means Git has been successfully installed.
Uploading Files to GitHub using Git
Next, we will upload a file to GitHub. Open your preferred code editor (e.g., Visual Studio Code), create a new folder, and create a new file inside it. For the purpose of this demonstration, let's create an
index.html file and write something in it.
Next, go to GitHub. If you don't have an account, create one by providing your email address, creating a password, and choosing a username. After creating the account, verify it through the confirmation email sent by GitHub.
In your GitHub account, create a new repository by clicking on the plus sign and selecting "New repository." Give your repository a name and optionally, a description. You can choose to keep it public or private. After creating the repository, you'll see some commands displayed, which we will use shortly.
Now, go back to the terminal and navigate to the folder where you created your project. Initialize this repository with Git by typing
git init. Type
git status to see the untracked files. Add these files to the staging area using the
git add . command. To check if the files have been added successfully, type
git status again.
git remote add origin [repository URL] where "[repository URL]" is the URL of the repository you created on GitHub. Next, type
git commit -m "First commit" to commit the changes, and then push the changes to GitHub using
git push -u origin master. You will need to authenticate this action by providing your GitHub username and a personal access token.
As of August 13, 2021, GitHub no longer supports password authentication. To authenticate, you need to create a Personal Access Token. Navigate to "Settings" in your GitHub account, go to "Developer Settings," then "Personal Access Tokens," and click on "Generate new token." Copy this token and paste it in the terminal when prompted for a password.
You've successfully pushed your files to GitHub. To verify this, navigate to your repository on GitHub, where you should see the
Congratulations, you've just installed Git on your MacBook M1 and pushed a file to GitHub. As a developer, these are invaluable skills that will streamline your coding process and enhance collaboration.
Don't forget to consistently update your repository with your latest work using the
git commit, and
git push commands. Happy coding!