Git Cheat Sheet

From Nearline Storage
Jump to navigation Jump to search

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

Update local copy of a forked project with changes made in the parent project

$ git remote add upstream git@framagit.org:medoc92/recoll-we.git
$ git fetch upstream
$ git checkout master
$ git rebase upstream/master
$ git push origin master [--force]