Using Git and Github - Basic Functions (Easy)
Tags: github, git, webdev, tutorial
Published: 2023-05-25 00:15:38

The purpose of this article is to guide you through some basic functions of Git in the order you'll need to use them with github.

Cloning a Repository
<div style="text-align: justify;">
Cloning a repository allows you to create a local copy of a remote repository from GitHub on your computer. This enables you to work with the repository's files, make changes, and contribute to the project. By cloning, you can access the codebase and collaborate with others without directly modifying the original repository. You need the repository's URL to clone it. GitHub provides a convenient "Code" button that offers the repository URL for you to copy. Here's how you do it:
</div>
- Open your web browser and go to https://github.com.
- Sign up for a GitHub account if you don't already have one. Follow the instructions provided to create your account.
- Once you're signed in, find the repository you want to clone. You can search for repositories using the search bar at the top of the GitHub page.
- Click on the repository name to open its main page.
- On the right-hand side of the repository's main page, you'll find a green "Code" button. Click on it.
- A dropdown will appear. Click on the clipboard icon to copy the repository's URL.
- Open the Terminal on your Linux computer.
- Navigate to the directory where you want to clone the repository. You can use the `cd` command followed by the directory path.
- In the Terminal, enter the following command, replacing `<repository-url>` with the URL you copied from GitHub:
```
git clone <repository-url>
```
- Press Enter to execute the command.
- Git will start cloning the repository, creating a local copy on your computer.

Making Changes
<div style="text-align: justify;">
After cloning the repository, you can make modifications to the files within it. This step involves using a text editor or IDE to add, modify, or delete files according to your requirements. You can write new code, fix bugs, update documentation, or perform any other necessary changes:
</div>
- Use a text editor or Integrated Development Environment (IDE) to make changes to the files within the repository.
- You can add, modify, or delete files according to your requirements.
- Save the changes after making modifications.

Checking Status
<div style="text-align: justify;">
Git keeps track of changes made to files in your local repository. The "git status" command allows you to see the current status of your local repository compared to the remote repository on GitHub. Checking the status helps you identify which files have been modified, which files are untracked (newly created), or which files have been deleted.
This step provides an overview of the changes you've made and helps you ensure you're ready to proceed to the next steps. To check the status:
</div>
- In the Terminal, navigate to the directory of the cloned repository. You can use the `cd` command followed by the repository's directory name.
- Enter the following command to check the status of your changes:
```
git status
```
- Press Enter to execute the command.
- Git will display a list of modified files or untracked files.

Staging Changes
<div style="text-align: justify;">
To include your changes in the next commit (upload), you need to stage them. Staging allows you to selectively choose which changes you want to include in the next commit.
Staging helps you organize and group related changes together, making your commits more meaningful and organized.
The "git add" command is used to stage changes. By specifying files or using the "." character, you can stage specific files or all the changes in your local repository.
</div>
- Enter the following command to stage all the changes:
```
git add .
```
- If you want to stage specific files, replace `.` with the file names or paths.

Commiting Changes
<div style="text-align: justify;">
Committing is the act of saving your staged changes to your local Git repository along with a descriptive message explaining the changes. Commits serve as checkpoints in your project's history, allowing you to track and revert changes if needed. Each commit should have a meaningful message that describes the purpose and intent of the changes made in that commit. The "git commit" command is used to create a commit, and the "-m" flag allows you to provide a commit message, so:
</div>
- After staging the changes, you need to commit them with a descriptive message.
- Enter the following command to commit the changes:
```
git commit -m "Descriptive commit message"
```
- Replace "Descriptive commit message" with a brief summary of the changes you made.
- Commit messages should be meaningful and describe the purpose of the commit.

Pushing Changes
<div style="text-align: justify;">
Pushing allows you to upload your committed changes from your local Git repository to the remote repository on GitHub. Pushing makes your changes visible to others working on the project and enables collaboration. It also ensures that your changes are backed up and accessible from anywhere. The "git push" command is used to push your committed changes to the remote repository on GitHub.
You will need to provide your GitHub username and password to authenticate and authorize the push. Summarizing:
</div>
- Once you have committed your changes, you can push them to the remote repository on GitHub.
- Enter the following command to push your changes:
```
git push
```
- Git will prompt you to enter your GitHub username and password.
- Type your credentials and press Enter. Note: When typing your password, you won't see any characters on the screen for security reasons.
- Git will upload your changes to the remote repository.
<div style="text-align: justify;">
That's it! You have successfully used the basic Git functions. You can now clone repositories, make changes, commit them, and push them to GitHub. Remember to navigate to the correct directory in the Terminal for each repository and replace `<repository-url>` with the actual URL of the repository you want to clone.
</div>