How to use git and GitHub

Contribute code to SolydXK and make it even better.
User avatar
Arjen Balfoort
Site Admin
Posts: 9219
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

How to use git and GitHub

Postby Arjen Balfoort » 04 Jul 2014 08:15

This tutorial I'll describe the basics of git in conjunction with GitHub. I'll limit myself to the terminal commands. Even if you prefer a GUI like Git Cola (I use that), it's important to understand how it all works underneath.

It's been a while. So, most of these things I did from memory, and collected from several documents. Please, help me improve this tutorial!


We start at creating your GitHub account
https://github.com
Save your user name and user e-mail address for when you need to configure git.


SSH Key
Generate an SSH key if you don't have one already

Code: Select all

ssh-keygen
Copy the generated SSH key

Code: Select all

cat ~/.ssh/id_rsa.pub
Go to your GitHub account settings at the top right of the page:
github-account-settings.png
github-account-settings.png (2.32 KiB) Viewed 7771 times
Select "SSH Key" in the left menu.
Click on the "Add SSH key" button, and paste the part ssh-rsa...user@my_host in the box to create a new key.


Install some packages

Code: Select all

sudo apt-get install ninja-ide python python3 python-gtk2 gir1.2-gtk-3.0 python-glade2 kiki git gitg gitk git-cola kompare libgtk2.0-dev poedit glade
Setup git
Use the information you used to create your GitHub account.

Code: Select all

git config --global user.name "my_user_name"
git config --global user.email "my_user_name@my_domain.com"
git config --global credential.helper cache
git config --global credential.helper "cache --timeout=3600"
What project?
Decide on what you want to work on. Perhaps you miss a feature, or you found a bug while working with the SolydXK tools. You might even have an idea for a new tool. You can also check out my TODO list.


Get the source
Go to SolydXK's GitHub: https://github.com/SolydXK

Select the repository you want to work on.
On the right you will see a menu, and at the bottom you will see "SSH clone URL".
github-ssh-clone.png
github-ssh-clone.png (3.11 KiB) Viewed 7771 times
Hit the copy button on the right to copy the URL to the clipboard.

Clone a repository
cd to a directory you want to save the source into, and run (live-installer used as an example):

Code: Select all

git clone git@github.com:SolydXK/live-installer.git
All sources are downloaded, and all necessary git configuration is saved in the hidden sub-directory ".git".


Branching
Working directly on the master git is generally a bad idea, except when you know you're going to be the only person working on that project. So, before you can start coding, you need to create a new branch. You give it the project name: the feature name, or bugs resolved on a certain section of the program.

Check the current branches (live-installer used as an example)

Code: Select all

cd live-installer
git branch
Will put out:
  • * master
Create a new branch

Code: Select all

git branch new_feature_name
(if you need to change a branch name: git branch -m another_name)

Check the branches again

Code: Select all

git branch
Which will output:
  • new_feature_name
    * master
Checkout the new branch
You'll be working on that branch instead of the master git.

Code: Select all

git checkout new_feature_name
And check the branches for the last time

Code: Select all

git branch
Outputs:
  • * new_feature_name
    master
Now open the source directory in ninja-ide, and you can start coding.


Committing the changes
When done, and tested, you need to get the changed code back to GitHub again.
Usually I get lazy by now, and use Git Cola to commit, and push the source to GitHub, but I'll describe the terminal commands here for reference.

Check the current status

Code: Select all

git status
This will give you detailed information on your changes.

Committing the changes to git

Code: Select all

git add -A
which will add all modified file, and remove files, but not add new files.

Add new files

Code: Select all

git add file1 file2 file3
Add a description

Code: Select all

git commit -m "Text of what was changed"
You can check out what is going to be commited like this:

Code: Select all

git diff --cached
Now it's time to push the commit to GitHub
Get the remote name (usually: origin)

Code: Select all

git remote
Push the branch

Code: Select all

git push -v origin new_feature_name
If you get this error message:

Code: Select all

ssh: Could not resolve hostname github.com: Name or service not known
you can test your SSH connection to github with this command:

Code: Select all

ssh -T -p 443 git@ssh.github.com
and confirm that you want to continue connecting.
Try to push to GitHub again.

If that still fails with the same error, you can add these lines to ~/.ssh/config:

Code: Select all

Host github.com
  Hostname ssh.github.com
  Port 443
Create a Pull Request
Go to the GitHub repository page (live-installer as an example): https://github.com/SolydXK/live-installer
In the right menu, select "Pull Requests".
Select "New pull request".
Select the new branch: new_feature_name
Add a comment and submit.

You can find a more thorough tutorial on git here: http://www.git-scm.com/docs/gittutorial

RavenLX has written a comprehensive post on Git Cola: http://forums.solydxk.nl/viewtopic.php?p=56800#p56800


SolydXK needs you!
Development | Testing | Translations

User avatar
Orbmiser
Posts: 829
Joined: 24 Aug 2013 22:58
Location: Portland,Oregon

Re: How to use git and GitHub

Postby Orbmiser » 14 Oct 2014 17:37

Thanks for this! As due to personal needs. My next step is learning to compile my own Kernel and Applications.

This will come in handy! ;)
.
Portfolio
http://500px.com/Orbmiser
Flickr
http://www.flickr.com/photos/orb9220/

SolydK - Kernel 3.16-2-amd64 - KDE 4.14.1 Update Pack: 2014.10.15

User avatar
Snap
Posts: 1244
Joined: 25 Aug 2013 20:01
Location: Spain

Re: How to use git and GitHub

Postby Snap » 15 Oct 2014 06:13

Indeed a great guide for noobs in this territory (like me). Thanks Schoelje.

Orb, don't skip this one either. Though the subject might be misleading and not interesting for someone, keep going. Aside of the main objective, it's the best guide on how to keep everything tidy and organized while packaging. Give it a go.
This likely means that your installation is broken. -Mr Pixbuf.

Image

Deleted User 2764

Re: How to use git and GitHub

Postby Deleted User 2764 » 07 May 2015 15:26

Thank you for this tutorial! Definitely needed it in my current project. :)

User avatar
Arjen Balfoort
Site Admin
Posts: 9219
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: How to use git and GitHub

Postby Arjen Balfoort » 03 Sep 2015 07:19

OP updated: solving SSH issue when pushing to GitHub.


SolydXK needs you!
Development | Testing | Translations

User avatar
ilu
Posts: 2420
Joined: 09 Oct 2013 12:45

Re: How to use git and GitHub

Postby ilu » 22 Sep 2015 17:21

I just felt like contributing and thought I could look through the german translation of the UM on github. There are some strange things there (english/german does not match) if I read the stuff right.
I'm really confused by your long and complicated explanation. I worked with github before and it just was "login" "load the page" "correct where necessary" "click fork" or something like that.
:?:

User avatar
Arjen Balfoort
Site Admin
Posts: 9219
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: How to use git and GitHub

Postby Arjen Balfoort » 22 Sep 2015 17:42

Github is easy, but using git and Github makes it more daunting.

Git does all the stuff locally (preparing your local project for git) and using git to create branches and synchronizing with Github. There are graphical tools to do the same, but this tutorial shows what is really happening and what is needed so that one can learn/understand the logic of using git.

Forking a Github repository will only copy that to your Github account. You'll have to get the files locally, adapt them, and push them back again to Github. That's what this tutorial is about.

It is still complicated, though.

As for translations, I've configured Transifex today: http://forums.solydxk.nl/viewtopic.php?p=56541#p56541
eselma had some trouble but maybe you are more lucky.


SolydXK needs you!
Development | Testing | Translations

Deleted User 2764

Re: How to use git and GitHub

Postby Deleted User 2764 » 08 Oct 2015 20:15

I started learning git-cola. Yeah, I know. I didn't think I'd go back to git but after a C project I completed, I am giving it another try. This time I'm not going to try using git inside of Eclipse!

Here's my notes:

Install these packages:
  • git (installs git-man and liberror-perl)
  • git-extras
  • git-cola
NOTE: gitk is also installed.

At the command line, do what Schoelje mentioned above. However, I also made a couple more changes. I changed how long git will cache my password so I don't have to keep typing it in. I have it set for 1 hour:

Code: Select all

$ git config --global credential.helper cache
$ git config --global credential.helper 'cache --timeout=3600'
timeout is in seconds.

Here's how I do my git-cola workflow:

Adding a Repository:

1. Create a new repository on the GitHub web site.
2. Run git-cola, click Clone.
3. On the Github web site, on the right side should the URL for the repository. Copy and paste it into the URL box in git-cola
4. Navigate to your git repository folder (I keep mine at: ~/Program_Data/Git). Click OK.

Adding and Updating Files to Repository:

1. In your file browser, navigate to git git repository folder. Copy any new files you want to push to the repository.
2. ALT+A (Staging Area - Stage Changed Files to Comit)
3. Stage - Stage All Untracked.
4. Click the gear icon by Commit.
5. Load Previous Commit Message - Initial commit.
6. Click the Commit button.
7. Action - Push. Select the Remote Branch. Click Push.

Sometimes you'll need to type in your GitHub login credentials after doing the Push. But if you set it up as I mention above, it will not always ask you. Instead it'll ask each hour after inactivity.

User avatar
Arjen Balfoort
Site Admin
Posts: 9219
Joined: 26 Jan 2013 19:36
Location: Netherlands
Contact:

Re: How to use git and GitHub

Postby Arjen Balfoort » 08 Oct 2015 22:01

Thanks, that was a good tip. Now I don't have to type my password that often anymore.

OP updated.


SolydXK needs you!
Development | Testing | Translations


Return to “Code”

Who is online

Users browsing this forum: No registered users and 1 guest