Github is a popular collaborative platform for programming. Files for a project are stored in repositories (repos) that are publicly accessible. Github users can contribute to growing and improving the repos through a process of fork-branch-edit-pull-merge. Scott Lowe has published a helpful tutorial for the fork and branch workflow.
This short article presents similar information from Scott's post and is a step-by-step instructions for publishing updates to an existing repo as (1) the owner and (2) a contributor. There may be other ways of updating a repo, so this article presents one way that works.
The beginning point for this article assumes that the repo has already been created on Github with a public repository url in the form https://github.com/owner/repo.git and that you have Github installed on your pc and can run commands with >git . All of the code commands are executed in Windows 10 command prompt which is run using "cmd". The repo for this example is https://github.com/footprintzero/foodwall
Repo owner
From command prompt update your git instance settings. You should be in the root directory one level above your repo. You only need to do this when you change repos or accounts ~root> git init ~root> git config - -global user.name footprintzero
Clone the repo onto your pc. This step should be skipped if you already have a local repo, otherwise you will see an exception mentioning that the folder already exists. ~root> git clone https://github.com/footprintzero/foodwall.git
Move into the local repo directory on your pc ~root>cd foodwall
Connect your git instance to the repo ~root\foodwall> git remote rm origin ~root\foodwall> git remote add origin https://github.com/footprintzero/foodwall.git
Sync your local copy to the master repo ~root\foodwall> git pull master master
Create a branch ~root\foodwall> git checkout -b owner_update
Apply edits to your local copy. Once you are ready, move to step 8
Push a commit request to your Github account ~root\foodwall> git add - -all ~root\foodwall> git commit -m "comments for owner update" ~root\foodwall> git push origin owner_update
You should be promoted to authorize by supplying your username and password
Login to your Github account and add commentary about your branch, create the pull request using the Github web browser interface.
As the owner - review the pull request and apply the changes via Merge.
Contributor to someone else's Repo
As a contributor, the steps of creating a branch, editing and pushing the commit request are identical to those as the owner. The difference is that instead of working on the master, you are working on a fork of the master that resides in your contributor Github account. This section will cover the differences between the owner and contributor, so read first the owner steps above as they will not be repeated in detail below.
Create a fork from the master. Login to your Github account and navitate to the master repo url https://github.com/footprintzero/foodwall . Next click "Fork" in the top right corner. Now you should have a new repo under your account. This is the fork. You only need to create a fork once and you can continue to re-use this fork for all subsequent updates. https://github.com/taylorhickem/foodwall
Update your github instance. Same as the owner, only in this case you use your contributor account. ~root> git config - -global user.name taylorhickem
Clone your fork and move into the directory ~root> git clone https://github.com/taylorhickem/foodwall.git ~root> cd foodwall
Connect your git instance and sync to the master repo using upstream command ~root\foodwall> git remote add upstream https://github.com/footprintzero/foodwall.git ~root\foodwall> git pull upstream master
The remaining steps are the same as owner for checking out a branch, editing and pushing a commit request. When prompted for credentials enter your contributor account username and password. Login to Github to review and submit your pull request, where you can add more detail to your pull request by summarizing the changes with HTML and file attachments. You have control of applying changes to your fork, however the repo owner retains control of merges to the master.
Using personal access token (PAT)
In July 2020, Github announced that they would no longer support login with username and password after 31 Aug 2021 and would require personal access tokens (PAT). The steps for creating and using a PAT are adapted from this article in the github documentation. Create a personal access token
verify your email address (if you haven't done so already)
login to your github account
navigate to Settings --> Developer Settings --> Personal access tokens
generate a new token
customize your token. Give it a name, expiration and access rights
take note of the token key (string). use it like a password
Login using a personal access token
use your PAT as a substitute for password when logging in ~root> git clone https://github.com/taylorhickem/foodwall.git Username: footprintzero Password: personal_access_token
Updating your credentials
main article: how to update your Git credentials on Windows
Windows Credentials Manager
Control Panel -> Credential Manager -> Generic Credentials -> Windows Credentials
Scroll to git:https://github.com and edit username and password. You can use either personal password or PAT
PyCharm project main article: change git user in IntelliJ IDEA
Navigate to the project root directory
Navigate into hidden directory called ".git"
search for "config" file and add the below code.
[user]
name = username
email = username@domain.com
Comments