Git: Difference between revisions

From London Hackspace Wiki
m (Updated lamarr stuff to landin.)
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
For version control of the IRC bot scripts we use [http://en.wikipedia.org/wiki/Git_%28software%29 git]. To contribute to projects such as the scripts accessible via robonaut (the bot), you'll need an account on Babbage.  We use Github for all common projects at Hackspace.
For version control of the IRC bot scripts we use [http://en.wikipedia.org/wiki/Git_%28software%29 git]. To contribute to projects such as the scripts accessible via robonaut (the bot), setup your [[LDAP]] account and login to [[Equipment/Landin#Chomsky|Chomsky]].  We use Github for all common projects at Hackspace.
 
If you get stuck with any of these steps, please pop onto [[IRC]] for tips.
 
 
<!-- From here should probably be in a Git tutorial page... -->
<!-- From here should probably be in a Git tutorial page... -->
== First time config ==
== First time config ==


Before you can start committing to the git repository, you need to configure your account on Babbage:
Before you can start committing to the git repository, you need to configure your account on [[Equipment/Landin#Chomsky|Chomsky]]:


  git config --global user.name "Jane Doe"
  git config --global user.name "Jane Doe"
Line 15: Line 19:
  ssh-keygen
  ssh-keygen


Press return when it asks you for the filename. If it then asks you to overwrite, say no ('''n''').  Otherwise, you can protect it with a password if you like. Then run:
Press return when it asks you for the filename.
 
If it then asks you to overwrite, say no ('''n''').  Otherwise, you can protect it with a password if you like.
 
Then run:


  cat ~/.ssh/id_rsa.pub
  cat ~/.ssh/id_rsa.pub


On Github, create a new entry in '''SSH Private Keys''' in '''Account Settings''', and paste the output of the last command into the '''Key''' area. You can also add the email address used above, and Github will automatically associate your commits with your account.
On Github, create a new entry in '''SSH Public Keys''' in '''Account Settings''', and paste the output of the last command into the '''Key''' area.
 
You can also add the email address used above to Github, and your commits will be automatically associated with your account.


== For each project ==
== For each project ==


The best way to contribute to a project with distributed version control is to create your own copy, and then push upstream any changes you make.
The best way to contribute to a project with distributed version control is to create your own copy on [[Equipment/Landin#Chomsky|Chomsky]], and then push any changes back to Github once you're happy with them.


To create a copy of the project:
To create a copy of the project:
Line 30: Line 40:
  git clone git://github.com/londonhackspace/irccat-commands
  git clone git://github.com/londonhackspace/irccat-commands
  cd irccat-commands
  cd irccat-commands
The URL here is the same as the one on Github, but with <code>git://</code> in front.  You may also see <code>.git</code> at the end - this doesn't make a difference.


== Committing ==
== Committing ==


First of all, create and edit the files as per usual. You can see what's changed by running:
First of all, create and edit the files as per usual. You can see what you've changed by running:


  git status
  git status
Line 39: Line 51:
or
or


  git diff
git diff


Now, to see to it that they're committed to the repo, do something like the following:
Now, to see to it that they're committed to the repo, do something like the following:
Line 50: Line 62:
  git commit -m "A useful, but short, message on the changes"
  git commit -m "A useful, but short, message on the changes"


This actually commits these changes, and attaches the comment after -m to the change to make it easy to see what changes you made at a glance. If you want to make a longer message, leave out -m, and you will be given a file in <code>vi</code> to edit.
This actually saves your changes, and attaches the message to explain what they do at a glance. If you want to make a longer message, leave out -m, and you will be given a file in <code>vi</code> to edit.


You should then check your commit history using:
You should then check your commit history using:


  git log
  git log


== Pushing ==
== Pushing ==
Line 70: Line 81:


  git push github
  git push github
Check on Github to see your changes in the commit history.


<!--... to here -->
<!--... to here -->
== Pull requests ==
== Pull requests ==


Pull requests are the easiest way to get your changes into the main repository.  Simply visit the main repository, and click on the '''Pull request''' button
Pull requests are the easiest and safest way to get your changes into the main repository.  Simply visit the main repository, and click on the '''Pull request''' button.  It will take you through packaging up the changes you've made into a form that can be commented on.
 
The other members who are already involved in the project will receive a notification of your request, but it's always a good idea to let people on IRC know what you're up to.
 
If you're confident with your knowledge of git, ask someone for push access to the projects on our main Github repository.  You'll need to update your remote paths, but you can then push changes to everyone else without any delay.


<!--
<!--
== If you've done it in place ==
== If you've done it in place ==


Now, you'll need to switch to the root user on babbage. As root:
Now, you'll need to switch to the root user on [[Equipment/Landin#Chomsky|Chomsky]]. As root:
  * '''git push''' #  This makes your changes available on the github repository, and thus available to others.
  * '''git push''' #  This makes your changes available on the github repository, and thus available to others.
-->
-->
[[Category:Reference]]
[[Category:Guides]]

Latest revision as of 18:09, 23 November 2018

For version control of the IRC bot scripts we use git. To contribute to projects such as the scripts accessible via robonaut (the bot), setup your LDAP account and login to Chomsky. We use Github for all common projects at Hackspace.

If you get stuck with any of these steps, please pop onto IRC for tips.


First time config

Before you can start committing to the git repository, you need to configure your account on Chomsky:

git config --global user.name "Jane Doe"
git config --global user.email jane@example.com
mkdir ~/git

This will update your ~/.gitconfig with the appropriate values, and is enough to make commits. You only need to do this once.

In order to contribute, you can then create a key for secure communication with Github:

ssh-keygen

Press return when it asks you for the filename.

If it then asks you to overwrite, say no (n). Otherwise, you can protect it with a password if you like.

Then run:

cat ~/.ssh/id_rsa.pub

On Github, create a new entry in SSH Public Keys in Account Settings, and paste the output of the last command into the Key area.

You can also add the email address used above to Github, and your commits will be automatically associated with your account.

For each project

The best way to contribute to a project with distributed version control is to create your own copy on Chomsky, and then push any changes back to Github once you're happy with them.

To create a copy of the project:

cd ~/git
git clone git://github.com/londonhackspace/irccat-commands
cd irccat-commands

The URL here is the same as the one on Github, but with git:// in front. You may also see .git at the end - this doesn't make a difference.

Committing

First of all, create and edit the files as per usual. You can see what you've changed by running:

git status

or

git diff

Now, to see to it that they're committed to the repo, do something like the following:

git add file1.sh data/file2.txt
git add file3*.py

This tells git which files you want to commit the changes for. Finally, use:

git commit -m "A useful, but short, message on the changes"

This actually saves your changes, and attaches the message to explain what they do at a glance. If you want to make a longer message, leave out -m, and you will be given a file in vi to edit.

You should then check your commit history using:

git log

Pushing

To push your changes to Github, from where you can share them, you need to do a little bit more set-up. First, fork the original project from Github to your own account. Then tell git where it is:

git remote add github git@github.com:jane/irccat-commands

You can check this using:

git remote -v

Then whenever you need to push, you can just issue this command:

git push github

Check on Github to see your changes in the commit history.


Pull requests

Pull requests are the easiest and safest way to get your changes into the main repository. Simply visit the main repository, and click on the Pull request button. It will take you through packaging up the changes you've made into a form that can be commented on.

The other members who are already involved in the project will receive a notification of your request, but it's always a good idea to let people on IRC know what you're up to.

If you're confident with your knowledge of git, ask someone for push access to the projects on our main Github repository. You'll need to update your remote paths, but you can then push changes to everyone else without any delay.