Git (Remote) - Start Contributing to FOSS
Push and pull from remote Git repositories and begin contributing code to free and open source software (FOSS) projects.
Introduction #
Git's distributed model revolutionized source code management. With Git, developers can clone a repository to manage their own. A clone of a repository on its own doesn't let a developer collaborate. They need to interact with the original repository.
An open source developer working on a repository hosted on Github, a platform for collaboration on software development, can't contribute without interaction with the repository hosted on Github. Git remotes let developers interact with other repositories hosted on other servers.
In the last tutorial, we learned how to get started using Git for your
project.
This tutorial helps you incorporate remote Git repositories to join millions of
developers in building FOSS software.
This tutorial will cover git remote
, git fetch
, git push
, and git pull
.
Contribute #
Git lets developers contribute version changes to other Git repositories. These repositories can exist on the same machine or a different machine.
To contribute:
- Create new Git repository
- Set a remote to the remote Git repository location
- Import code from remote
- Edit code in new local Git repository
- Create new version with changes
- Send new version with changes to remote
Create Git Repo #
To create a new Git repo, run the git init
command in the project folder.
Important
This step assumes that you opened a terminal and the current working directory is the project directory. Read the previous part of this Git tutorial to learn how to open a terminal and change the current working directory to the project directory.
Set Remote Repository #
To set the location of the remote Git repository, run the git remote add
command followed by an alias for the remote repository (e.g. origin
) and the
URL denoting the location of the remote Git repository (e.g. <URL>
).
The following command adds a remote named origin
with the URL of the Godot
game engine (https://github.com/godotengine/godot
).
$ git remote add origin https://github.com/godotengine/godot
Import Code #
To pull code from the remote repository into the local repository, run the git pull
command followed by an alias for the remote repository (e.g. origin
) and
the branch to pull code from.
By default, code is added on the master
branch, although some recent
repositories use main
.
The following command pulls code from the master
branch in a remote repository
named origin
:
$ git pull origin master
Edit Code #
To edit code, open a text editor and write text to a file. This tutorial assumes satisfactory knowledge and intention for how to edit code.
Create New Version #
To create a new version of the project with the edits, run the git commit
command with a commit message passed in with the -m
option.
The following command creates a new version of the project with the commit message "Made edits":
$ git commit -m "Made edits"
Send New Version #
To send the new version created to the remote repository, run the git push
command with an alias for the remote repository (e.g. origin
) and the branch
to send the new version to.
The following command sends the code updates to the branch master
on a remote
repository named with the alias origin
:
$ git push origin master
Conclusion #
This tutorial helped you contribute code to a remote Git repository. With this knowledge, you can contribute code to a free and open source project. In the next tutorial, you'll learn more tricks with Git.
References #
- Pro Git by Scott Chacon and Ben Straub
License #
This work is licensed under CC BY 4.0.