How to Git (Part 1): Git and GitHub Skip to main content

How to Git (Part 1): Git and GitHub


 Git is a version control system that is used for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files. In this post, we will show how to create a repository using Git and push it to GitHub using git commands. 
You need to install Git on your computer before you can use it. The most recent version should probably be updated even if it is already installed. You can either download the source code and compile it yourself, or you can install it as a package or through another installer. To install Git follow the steps explained in this tutorial 
Once you have installed Git, you can use it to initialize a new repository for your project by running the following command in a terminal or command prompt:
$ cd ~/Users/Abdul 
$ mkdir NewRepo
$ git init
This will create a new directory called .git in your project folder named as NewRepo, which will be used by Git to store information about the repository.
To start tracking changes to your code with Git, you need to add the files to the repository. This is done using the git add command, followed by the names of the files you want to add. For example, to add all the files in your project folder, you can use the git add . command. For Example, let's add one text file to the project and then track the changes. 
$ touch Hello.txt
Once you have added the file, you can commit the changes to the repository using the git commit command. This will create a new commit, which is a snapshot of your code at a particular point in time. It is a good idea to include a commit message with each commit, which describes the changes that were made. You can do this by passing the -m flag to the git commit command, followed by your commit message in quotation marks.
For example:
$ git commit -m "Added new File"

Now if you type git status command, you can find out that Git has added the file to the staging environment.

Pushing the created Repo onto GitHub

You don't need to use GitHub if you only want to monitor your code locally. But if you want to collaborate, you can utilize GitHub to change the project's code together.
to do this, you first need to create a new repository on GitHub, name it, and provide a brief description. Go to the GitHub home page after logging in to start a new repository. The "New repository" option can be found in the top right corner of the navbar, underneath the plus sign next to your profile picture:

Once you're done, click the "Create repository" button to create your new repository.
GitHub will ask you if you want to add an existing local repo or build a new one from start. In this instance, since we've already started a brand-new repository locally, we want to push it to GitHub, therefore adhere to the instructions in the part under "...or push an existing repository from the command line":
$ git remote add origin https://github.com/abdulkader902017/NewRepo.git
$ git push -u origin master
With that said, we showed you how to create a new Repo using Git on your own local Computer and then push it onto GitHub to be publicly available for everyone who would to contribute. Finally, there are many other commands and features in Git that you can use to manage your repository and collaborate with others. To learn more, you can read the Git documentation or take an online course on Git.



Comments

You may like

Latest Posts

SwiGLU Activation Function

Position Embedding: A Detailed Explanation

How to create a 1D- CNN in TensorFlow

Introduction to CNNs with Attention Layers

Meta Pseudo Labels (MPL) Algorithm

Video Classification Using CNN and Transformer: Hybrid Model

Graph Attention Neural Networks