Difference between revisions of "Git Cheat Sheet"

From Nearline Storage
Jump to navigation Jump to search
m
m
Line 17: Line 17:
 
<code>$ git commit -a -m "Description"</code>
 
<code>$ git commit -a -m "Description"</code>
 
<br /><code>$ git push</code>
 
<br /><code>$ git push</code>
 +
 +
=== Submit Changes To A Project You Don't Own ===
 +
 +
Create a pull request:
 +
 +
: Click the <code>Fork</code> button in the project on the GitHub web site to make your own copy of the project in your repository
 +
: <code>$ git clone https://github.com/dlk3/projectname.git</code> - get a local copy of the fork
 +
: <code>$ git checkout -b new_branch_name</code> - create a new branch to work with in your repo
 +
: <code>$ git remote add upstream https://github.com/ownername/projectname</code> - link to the original project
 +
: <code>$ git remote set-url origin git@github.com:dlk3/projectname.git</code> - switch to SSL authentication
 +
: Make whatever changes you need to
 +
: <code>$ git status</code> - check for changes that need to be committed
 +
: <code>$ git commit -a -m "Descriptive text"</code>
 +
: <code>$ git push -u origin new_branch_name</code>
 +
: The upstream project will now have a <code>Compare & pull request</code> button that you can use to submit a pull request to the upstream project for your changes
  
 
[[Category:Linux]]
 
[[Category:Linux]]
 
[[Category:Bash]]
 
[[Category:Bash]]

Revision as of 16:21, 15 December 2020

Create A New Project Repository

  1. Go to https://github.com/new and create a new repository (project)
  2. Create a directory on the local workstation and populate it with the source files, then in that directory do:
$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add origin git@github.com:dlk3/projectname.git
$ git push -u origin master

Pull Down Changes Made At Remote Repository

$ git pull origin master

Push Local Changes Up To Remote Repository

$ git commit -a -m "Description"
$ git push

Submit Changes To A Project You Don't Own

Create a pull request:

Click the Fork button in the project on the GitHub web site to make your own copy of the project in your repository
$ git clone https://github.com/dlk3/projectname.git - get a local copy of the fork
$ git checkout -b new_branch_name - create a new branch to work with in your repo
$ git remote add upstream https://github.com/ownername/projectname - link to the original project
$ git remote set-url origin git@github.com:dlk3/projectname.git - switch to SSL authentication
Make whatever changes you need to
$ git status - check for changes that need to be committed
$ git commit -a -m "Descriptive text"
$ git push -u origin new_branch_name
The upstream project will now have a Compare & pull request button that you can use to submit a pull request to the upstream project for your changes