- You can maintain the history of your project. Afterwards, you can go back in time to check which person made which kind of change to which file in the project, what kinds of changes were made, etc.
- It's a version control system, where you basically capture a snapshot of a project and store it as a 'version'.
Git
is a version control system, andGithub
is the front-end platform that allows us to see & manage the repositories.
-
Fork the Repository to your own account. This creates a clone of the repository in your own GitHub account.
-
Get the HTTPS link for the forked repository, then clone it to your own system.
$ git clone <LINK-TO-REPOSITORY>
Note: Once the project has been cloned, you can do everything else on your own system.
-
Check the
README.md
for the project. If it has aCONTRIBUTING.md
guide, go through it. -
Make the necessary changes to the files.
-
Stage your changes, then commit them.
$ git status # Check status $ git add . # Add your changes $ git commit -m 'MESSAGE' # Commit your changes with a message
-
You can't push your changes directly in the main branch of the repository, since it will lead to a lot of errors & conflicts. So, you need to create a new branch. Here's how you do it:
$ git branch <BRANCH-NAME> # Try to keep the branch name relevant. $ git checkout <BRANCH-NAME> # Optional, this tells git to push all future commits to this branch.
-
Finally, push your changes to the branch you created.
$ git push origin changes # Assuming the branch name is 'changes'.
-
The final step is to submit a pull-request. You need to do this on the Github page.
A pull request is a way for you to tell the project maintainers that you have made some changes and would like them to review & integrate them in the main branch of the remote repository.
Once you submit a pull request, you will have to check up with the maintainers from time to time, and make further changes if they need you to. -
Now that your pull request is created, you will automatically be subscribed to notifications regarding to any activity. Once the commit is reviewed by the maintainers, they will merge your commit with the original project.
Note: Since we're pushing to a new repository we just created, we will be committing directly to the main branch. However, under normal circumstances, you should never directly commit to the main branch since the code is used by software that runs in production. You should always create your own branch and add a pull request for your code to be merged with the main branch. Check above for more details.
-
Create a new repository on Github by going to
Profile
>Your Repositories
>New
.
-
Clone the repository to your local machine. This effectively creates a folder with the same name as the remote repository, and set the checkout branch to main. Note: Checkout branch: The branch git is set to push all the committed changes to, unless specified otherwise.
# Put your own Repository URL here $ git clone https://github.com/sayande717/temp.git
-
Switch to the repository, make some changes.
$ cd temp # Change to the directory $ echo "hello, world!" >> file.txt # Create a new file and add a line to it
-
Add your files & commit them.
$ git add . # Add all files $ git commit -m 'ADD: file.txt' # Commit them with a message 1 file changed, 1 insertion(+) create mode 100644 file.txt
-
Push your changes to the main branch. After this, you can see the changes in your remote repository.
$ git push origin main # Push to the main branch Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 226 bytes | 226.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/sayande717/temp.git * [new branch] main -> main
git status
: Use this to check the current status at any time, as long as you're in the repository.git log
: Use this to get a history of all commits you made, in your local machine.- If you're contributing to a repository that's not yours, make sure you create a separate branch before committing (i.e. never commit to the main branch). Also, if you're working on distinct features/files within the same repositories, create separate branches for each of them.
- A pull request can be associated with only 1 branch, so if you make further changes on the same branch, git will auto-link it to your current pull request.
- Make sure you sync your forked repository from time to time to stay up-to-date with the upstream repository.