Difference between revisions of "John's GitHub page"

From ProgClub
Jump to: navigation, search
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
OK. Hi there. I'm [[User:John|John]]. So recently I've made some modifications to code that is hosted on [https://github.com/ GitHub], as you can see in [https://github.com/jj5 my account]. I'm new and still learning the process, so here's what I've figured out:
 
OK. Hi there. I'm [[User:John|John]]. So recently I've made some modifications to code that is hosted on [https://github.com/ GitHub], as you can see in [https://github.com/jj5 my account]. I'm new and still learning the process, so here's what I've figured out:
  
= Tools =
+
= Get info about your upstream remote origin =
 +
 
 +
The following command is similar to <code>svn info</code>:
 +
 
 +
$ git remote show origin
 +
 
 +
= Revert local changes =
 +
 
 +
See [https://stackoverflow.com/a/1146981/868138 here]:
 +
 
 +
If you want to revert changes made to your working copy, do this:
 +
 
 +
git checkout .
 +
 
 +
If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:
 +
 
 +
git reset
 +
 
 +
If you want to revert a change that you have committed, do this:
  
== Git ==
+
git revert <commit 1> <commit 2>
  
So the git command-line tool is pretty much essential. Install on Debian with: apt-get install git
+
If you want to remove untracked files (e.g., new files, generated files):
  
== SourceTree ==
+
git clean -f
  
[https://www.sourcetreeapp.com/ SourceTree] comes recommended as a GUI for beginners and pros alike. Install on Debian with: oh, dear. It's not a Linux tool. Nevermind.
+
Or untracked directories (e.g., new or automatically generated directories):
  
= Syncing a fork =
+
git clean -fd
  
== Configure your upstream remote ==
+
= Configure your upstream remote =
 +
 +
# list current remotes:
 +
$ git remote -v
 +
 +
# add an upstream remote if there isn't one:
 +
$ git remote add upstream git@github.com/orig-owner/orig-repo.git
 +
 +
# verify your remotes contains your new remote:
 +
$ git remote -v
  
If you haven't already done so:
+
= Syncing a fork (rebase method) =
  
# list current remotes: git remote -v
+
Be sure to [[#Configure_your_upstream_remote|configure your upstream remote]] first.
# add an upstream remote if there isn't one: git remote add upstream git@github.com/orig-owner/orig-repo.git
 
# verify your remotes: git remote -v
 
  
== Fetch from upstream repository ==
+
# ensure your copy of upstream is fully up-to-date
 +
$ git fetch upstream
 +
 +
# ensure that you are on your topic branch
 +
$ git checkout topic-branch
 +
 +
# this removes your commits, pushes in the commits from upstream added since
 +
# you forked and branched, and then re-adds your commits
 +
$ git rebase upstream/master
 +
 +
# now fix any conflicts that couldn't be merged automatically
 +
# (which might warrant its own section)
  
# fetch upstream branches/commits: git fetch upstream
+
At this point your topic branch is up to date with the latest upstream changes, so you can push the topic branch back up to your origin (you will likely need to `git push -f` because your rebase has rewritten history) and create the PR.
  
== Switch to local master ==
+
= Syncing a fork (merge method) =
  
# check out your fork's local master: git checkout master
+
Be sure to [[#Configure_your_upstream_remote|configure your upstream remote]] first.
  
== Merge upstream/master to local master ==
+
# fetch branches/commits from upstream repository:
 +
$ git fetch upstream
  
# sync your local master with upstream: git merge upstream/master
+
# switch to your fork's local master:
 +
$ git checkout master
  
== Push your local master back to your fork on GitHub ==
+
# merge upstream/master to local master:
 +
$ git merge upstream/master
  
# push your fork: git push origin
+
# push your local master back to your fork on GitHub:
 +
$ git push origin
  
 
= Submitting a patch via GitHub =
 
= Submitting a patch via GitHub =
Line 62: Line 102:
  
 
Note: you can create a branch and check it out with one command: git checkout -b branch-name
 
Note: you can create a branch and check it out with one command: git checkout -b branch-name
 
Question: is 'switch' the correct verb for changing between branches?
 
  
 
== Make your changes ==
 
== Make your changes ==
Line 96: Line 134:
 
= Links =
 
= Links =
  
 +
* [https://gist.github.com/elikem/693985e24e8ddd263f1a84b06ac71186 99% of the Git commands you'll need at work, demonstrated in a single script]
 
* [https://help.github.com/articles/configuring-a-remote-for-a-fork/ Configuring a remote for a fork]
 
* [https://help.github.com/articles/configuring-a-remote-for-a-fork/ Configuring a remote for a fork]
 
* [https://help.github.com/articles/syncing-a-fork/ Syncing a fork]
 
* [https://help.github.com/articles/syncing-a-fork/ Syncing a fork]
Line 101: Line 140:
 
* [https://help.github.com/articles/creating-a-pull-request/ Creating a pull request]
 
* [https://help.github.com/articles/creating-a-pull-request/ Creating a pull request]
 
* [https://help.github.com/articles/creating-a-pull-request-from-a-fork/ Creating a pull request from a fork]
 
* [https://help.github.com/articles/creating-a-pull-request-from-a-fork/ Creating a pull request from a fork]
 +
 +
= Tools =
 +
 +
== Git ==
 +
 +
So the git command-line tool is pretty much essential. Install on Debian with:
 +
 +
# apt-get install git
 +
 +
== SourceTree ==
 +
 +
[https://www.sourcetreeapp.com/ SourceTree] comes recommended as a GUI for beginners and pros alike. Install on Debian with: oh, dear. It's not a Linux tool. Nevermind.
 +
 +
== GitEye ==
 +
 +
[https://www.collab.net/products/giteye GitEye] is a git GUI recommended by [[User:Jedd|Jedd]]. It's beer free rather than speech free. The download page is [https://www.collab.net/content/collabnet-giteye-linux-64-bit here].

Revision as of 07:02, 9 October 2019

OK. Hi there. I'm John. So recently I've made some modifications to code that is hosted on GitHub, as you can see in my account. I'm new and still learning the process, so here's what I've figured out:

Get info about your upstream remote origin

The following command is similar to svn info:

$ git remote show origin

Revert local changes

See here:

If you want to revert changes made to your working copy, do this:

git checkout .

If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:

git reset

If you want to revert a change that you have committed, do this:

git revert <commit 1> <commit 2>

If you want to remove untracked files (e.g., new files, generated files):

git clean -f

Or untracked directories (e.g., new or automatically generated directories):

git clean -fd

Configure your upstream remote

# list current remotes:
$ git remote -v

# add an upstream remote if there isn't one:
$ git remote add upstream git@github.com/orig-owner/orig-repo.git

# verify your remotes contains your new remote:
$ git remote -v

Syncing a fork (rebase method)

Be sure to configure your upstream remote first.

# ensure your copy of upstream is fully up-to-date
$ git fetch upstream

# ensure that you are on your topic branch
$ git checkout topic-branch

# this removes your commits, pushes in the commits from upstream added since
# you forked and branched, and then re-adds your commits
$ git rebase upstream/master 

# now fix any conflicts that couldn't be merged automatically
# (which might warrant its own section)

At this point your topic branch is up to date with the latest upstream changes, so you can push the topic branch back up to your origin (you will likely need to `git push -f` because your rebase has rewritten history) and create the PR.

Syncing a fork (merge method)

Be sure to configure your upstream remote first.

# fetch branches/commits from upstream repository:
$ git fetch upstream
# switch to your fork's local master:
$ git checkout master
# merge upstream/master to local master:
$ git merge upstream/master
# push your local master back to your fork on GitHub:
$ git push origin

Submitting a patch via GitHub

Fork the upstream repository into a project in your account

  1. go to GitHub
  2. login
  3. navigate to the project repository you want to fork
  4. click 'Fork' on the top right

Clone your fork

  1. open a terminal on your workstation
  2. change dir to your github directory (I use /home/jj5/repo/git/github/jj5)
  3. clone your fork (using SSH) with: git clone git@github.com/jj5/MyProject.git

Make a topic branch in your fork

You can read about what a topic branch is.

  1. open a terminal on your workstation
  2. change dir to your github fork (e.g. /home/jj5/repo/git/github/jj5/MyProject)
  3. create a branch with: git branch branch-name
  4. switch to your new branch: git checkout branch-name

Note: you can create a branch and check it out with one command: git checkout -b branch-name

Make your changes

So edit files, add files, etc.

Tell git about new files

If you've added files include them in git with: git add file.name

Commit your changes on the topic branch

To commit your changes: git commit -a -m 'What you did...'

Push your changes into your fork at GitHub

To push your topic branch upstream: git push --set-upstream origin branch-name

Create a pull request

  1. go to GitHub
  2. login
  3. navigate to your fork in your account
  4. in the top left select your topic branch for the Branch drop down
  5. click 'New pull request'
  6. the 'base fork' should be the project you forked from that you wish to contribute to
  7. the 'base' branch is the branch you want to merge with (probably 'master'?)
  8. the 'head fork' is where your proposed changes are (i.e. in your fork)
  9. the 'compare' branch is the branch that has your changes (i.e. your topic branch)
  10. add a message, check your changes, and submit your way to victory!

Links

Tools

Git

So the git command-line tool is pretty much essential. Install on Debian with:

# apt-get install git

SourceTree

SourceTree comes recommended as a GUI for beginners and pros alike. Install on Debian with: oh, dear. It's not a Linux tool. Nevermind.

GitEye

GitEye is a git GUI recommended by Jedd. It's beer free rather than speech free. The download page is here.