How to make and submit changes to source code on GitHub

GitHub is an awesome collaborative software development tool. There is a lot of documentation on working with git: in the program's help and on the Internet.

Being very flexible and with many commands and options, git can be confusing when you first get to know it. The git options and commands should be studied carefully, but this post is a dirty and short guide that shows you step by step how to make changes to a program hosted on GitHub and how to submit your changes to the author.

Before sending your changes to the code to the author of the program, it is strongly recommended that you familiarize yourself with his wishes. They can be associated with both programming style (specifics of naming variables, for example) and formatting features (using the tab key or four spaces, for example). Even if the author did not write their wishes, it is highly recommended to follow the style of the code you are editing.

Source code edit permission on GitHub

The procedure for changing the source code on GitHub differs depending on whether you have the permission to change the source code of a repository or not.

You can directly edit a repository on GitHub in the following cases:

  • you are the owner of the repository
  • you are granted permissions to edit a specific repository by its owner

In this case, the editing procedure is as follows:

  • you clone the source code to your local computer
  • make changes to the source code
  • push changes to the repository

If you do not have permission to edit the repository, but want to suggest a change to the source code, then you need to Fork the original repository.

Next, you go through three familiar stages for your fork:

  • you clone the source code to your local computer
  • make changes to the source code
  • push changes to the repository

After that, you submit changes to the original repository, this is called “Pull request”.

How to edit source code on GitHub

I'll show you part of a real workflow on real code here.

Situation: in the airgeddon program in the EvilTwin branch, I need to make changes to some lines. I start by cloning the code to my local drive:

git clone https://github.com/v1s1t0r1sh3r3/airgeddon.git -b EvilTwin

Note that I am using the -b switch, followed by the name of the EvilTwin branch. By default, the newest branch is cloned (the branch in which the most recent changes were made). Since the default name is master, this is usually the branch that is cloned.

The names of branches and features of the workflow can be different for each project – and they are discussed within the team or available in the form of public rules.

The source code can be edited in your favorite editor or IDE. After completing the edits, on the command line, go to the directory with the program and execute there:

git status

Information about the status (file changed) and tips on what to do next are displayed:

Add the file(s) in which the changes were made:

git add airgeddon.sh

And again we look at the status:

git status

We need to write a comment on what we did with the code:

git commit -m "Updating Russian translation (minor fixes)"

We get approximately the following information:

[EvilTwin 39b8960] Updating Russian translation (minor fixes)
 1 file changed, 8 insertions(+), 8 deletions(-)

If you're curious, you can see the status again:

git status

The information received and the hint indicate that everything is ready to send our changes to GitHub. To do this, I execute the command (EvilTwin in this case is the name of the branch to which I am committing):

git push origin EvilTwin

You will be asked for your username (e-mail) and password on GitHub and the following information will be displayed:

Подсчет объектов: 3, готово.
Delta compression using up to 3 threads.
Сжатие объектов: 100% (3/3), готово.
Запись объектов: 100% (3/3), 420 bytes | 0 bytes/s, готово.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/v1s1t0r1sh3r3/airgeddon.git
   04d1fb4..39b8960  EvilTwin -> EvilTwin

PLEASE NOTE: Since August 13, 2021, support for password authentication has been removed and now you need to use a token. For details, see Error “remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead” (SOLVED).

Finally, you can check the status again:

git status

Leave Your Observation

Your email address will not be published.