Let's learn GitHub! Feel free to use the issues in this git sample Project to learn Git and Github. Add commands you learned that are useful to make this like documentation. Hopefully it will be fun and teach you so you can contribute to bigger projects in the future.
To contribute to a project the first thing you have to do is:
Commands:
git clone [url] myproject
Explanation:
git clone
allows us to specify that we will clone the repository. url
refers to the project where we want to contribute in this case https://github.com/namruthahari/Sample-Git-Repo.git
.myproject
refers to the name we want to give to the project in our local files, in case we don't give it a name it will use the repository name.Example:
git clone https://github.com/namruthahari/Sample-Git-Repo.git myproject
After cloning the repository you can start contributing to any file in the project. In our case we will create an index.html
file.
We have created the index.html
file now we want to keep track of that file.
The first thing we will do is:
git add .
Explanation:
git add .
adds the changes that have been made to our repository, in this way we will send the changes to wait on the stage.
Check the status of our files with the command:
git status -s
Explanation:
git status
we are telling git that we want to check the status of the files we have added.-s
is a shorthand for output information indicating what change has been made to the file and the file name.output:
M index.html
Now let's say we have added some information in the index.html
file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tutorial</title>
</head>
<body>
<h1>Git and GitHub</h1>
</body>
</html>
After adding the information, we will do the same process:
We check the status with git status -s
Output:
M index.html
git add -A
command to add the changes made to the scenario.Explanation:
-A
adds the files that have been modified. This command is mostly used to avoid adding files that have been created on the fly.We have already added our changes to the scenario, now we want to save those changes in a commit.
git commit -m "Add index.html"
Explanation:
git commit
creates an instant snapshot of all the code we have written and files we have added.git commit -m " "
is used as a quick way to add a message."Add index.html"
inside the quotes has to be a short message explaining what we have done.From there, we can see all the commits we have done with the command:
git log --pretty=oneline
Explanation:
git log
shows us the history of commits we have performed.git log --pretty=oneline
is a shorthand for displaying the commits in a reduced form on a single line.After that we can upload our contribution to our repository. To do this the first thing we have to do is:
git branch -M main
note: the name we specify in this example is main, but you can give any name to your branch, e.g. dev or example.
explanation:
git branch -M
helps us to change the branch name to a new name, so when using the command we have to specify the branch name, example: git branch -M dev
.
git remote add origin [url]
Explanation:
Example:
git remote add origin https://github.com/namruthahari/Sample-Git-Repo.git
git push origin main
Explanation:
When everything is ready to commit to the official repository we will get a message that will say the following:
This branch is 1 commit ahead of namruthahari:main. right there it asks us to make a Pull request or a compare.
What we will do is the following:
Want to learn how to contribute?
You can take this repository as an example to take your first steps. Follow the knowledge you have already acquired for yourself or this small tutorial.
**Do you want to learn more about Git and GitHub?
Documentation, books and videos about Git: Click here
GitHub documentation: Click here