Git for Beginners: A Step-by-Step Guide to Installing and Using Git

Git for Beginners" is a tutorial that provides a step-by-step guide to installing and using Git on various operating systems. It covers the basics of Git, including how to create and clone repositories, make commits, and collaborate with others.

image description

Git for Beginners: A Step-by-Step Guide to Installing and Using Git

"Git for Beginners" is a tutorial that provides a step-by-step guide to installing and using Git on various operating systems. It covers the basics of Git, including how to create and clone repositories, make commits, and collaborate with others. This tutorial is suitable for beginners who are new to Git and want to learn how to use it effectively.

Git is a free and open-source distributed version control system that is widely used for software development and collaboration. Here are the steps to install Git on various operating systems:

Windows

  1. Download the latest Git for Windows installer from the Git website.
  2. Run the installer and follow the prompts to complete the installation.
  3. Open the Start menu and search for "git bash".
  4. Launch the Git Bash application.

macOS

  1. Download the latest Git for macOS installer from the Git website.
  2. Run the installer and follow the prompts to complete the installation.
  3. Open the Terminal application.

Linux

Git is usually included with the default package manager on most Linux distributions. To install Git on a Debian-based distribution (such as Ubuntu), run the following command:

sudo apt-get install git

On a Red Hat-based distribution (such as CentOS), run the following command:

sudo yum install git

If you are using a different Linux distribution, refer to the distribution's documentation for information on how to install Git.

After installing Git, you can confirm the installation by running the following command:

git --version 

output:
git version 2.37.1

This will print the version of Git that was installed.

Keep in mind that you will need to download Git before you can install it. To download Git, visit theGit websiteand click on the "Download" button. This will take you to a page with download links for the latest version of Git for each supported operating system. Choose the appropriate link for your operating system and download the Git installer. Once the download is complete, follow the steps above to install Git on your system.

Git setup for demo project:

To set up Git and GitHub on your computer, you will need to perform the following steps:

  1. Install Git on your computer. You can download the installer from the official Git website (https://git-scm.com/).

  2. Open a terminal or command prompt and type git --version to verify that Git has been installed successfully.

  3. Configure your Git user name and email address. This is important because every Git commit uses this information, and it is immutably baked into the commits you start creating:

$ git config --global user.name "Your Name"
$ git config --global user.email "your_email@example.com"
  1. Create a new Git repository. A repository is a directory that contains your project files and stores each file's revision history. To create a new repository, navigate to the directory where you want to store your project and type the following command:
$ git init
  1. Add files to your repository. To add files to your repository, use the git add command. For example, to add all files in the current directory and all its subdirectories, you can use the following command:
$ git add .
  1. Commit your changes. After you have added files to your repository, you need to commit your changes to save them to the repository. You can do this by using the git commit command. Be sure to include a commit message that describes the changes you have made.
$ git commit -m "added new files"
  1. Create a new repository on GitHub. To create a new repository on GitHub, log in to your account and click the "New" button in the top right corner of the dashboard. Enter a name for your repository and a brief description, and then click the "Create repository" button.

  2. Push your changes to the remote repository. To push your changes to the remote repository on GitHub, you will need to add a remote repository and then use the git push command to push your changes to the remote repository.

$ git push origin master

Git on your local computer:

Setting up Git on your local computer is relatively simple, and once it's set up, you can use it to track changes to your code and collaborate with others using GitHub. Here's a step-by-step guide for setting up Git on your local computer:

  1. Install Git: The first step is to install Git on your local computer. You can download the latest version of Git from the official website at git-scm.com. Follow the installation instructions for your operating system.

  2. Set your username and email: After installing Git, you'll need to set your username and email. This will be used to identify you as the author of the commits you make. You can set your username and email by running the following commands in the terminal:

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
  1. Generating SSH Key: SSH keys are used to securely connect to remote repositories and Github require you to use them, you can generate your ssh key by running following command in terminal
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"

This will generate an ssh key and save it in the default location(~/.ssh/id_rsa)

  1. Adding the ssh key to your Github account: After generating ssh key, add it to your Github account by following these steps:
  • Open the terminal and run:
cat ~/.ssh/id_rsa.pub
  1. This will print your ssh key, copy it.
  2. Go to your Github settings, then click on SSH and GPG keys.
  3. Click on 'New SSH key' button
  4. Enter a title for your key, paste the ssh key into the key field, then click Add SSH key
  5. Creating a new repository: Once you've set up Git on your local computer, you can create a new repository. To do this, go to GitHub and click the "New repository" button. Give your repository a name and click the "Create repository" button.

  6. Clone the repository: To clone the repository to your local machine, copy the repository's URL from the "Clone or download" button on the GitHub page. Then, open a terminal and run the following command:

git clone https://github.com/username/repositoryname.git

This will create a new directory called "repositoryname" on your local machine, with the contents of the repository.

  1. Make changes: Open the files in the repository directory on your local machine and make any changes you want. You can use your favorite text editor or IDE to edit the files.

  2. Commit the changes: To commit the changes, run the following command in the terminal:

git commit -am "Commit message"

Replace "Commit message" with a brief description of the changes you made.

  1. Push the changes: To push the changes to the remote repository on GitHub, run the following command in the terminal:
git push origin master

This will upload the changes to the master branch of the repository on GitHub.

And that's it! You've now set up Git on your local computer and created a new repository on GitHub. You can now use Git to track changes to your code and collaborate with others using GitHub.

Please let me know if you have any questions or need further clarification.

Extra Settings:

Set your text editor: Git allows you to use a text editor to write commit messages and other messages. By default, Git uses the vi editor, but you can change it to any other editor of your choice. For example, to use the nano editor, use the following command:

git config --global core.editor nano

Set your default push behavior: When you push changes to a remote repository, you need to specify which branch you want to push to. By default, Git pushes only the current branch to the remote repository. If you want to change this behavior, you can use the push.default configuration option. For example, to push all branches to the remote repository, use the following command:

git config --global push.default current

 

DigitalOcean Referral Badge

DigitalOcean Sign Up : If you don't have a DigitalOcean account yet, you can sign up using the link below and receive $200 credit for 60 days to get started: Start your free trial with a $200 credit for 60 days link below: Get $200 free credit on DigitalOcean ( Note: This is a referral link, meaning both you and I will get credit.)


Latest From PyDjangoBoy

👩💻🔍 Explore Python, Django, Django-Rest, PySpark, web 🌐 & big data 📊. Enjoy coding! 🚀📚