Difference between revisions of "User:Cyrusty/Git"
(Created page with "== Lesson #2: Setting up a GitHub account == I have now created an account on [https://github.com/ GitHub] which a web application allowing people and teams to work on their c...") |
m (→Lesson #2: Setting up a GitHub account) |
||
Line 16: | Line 16: | ||
I could then select it, copy it and paste it into the text-box in [https://github.com/settings/keys GitHub's page for add a new key]. | I could then select it, copy it and paste it into the text-box in [https://github.com/settings/keys GitHub's page for add a new key]. | ||
+ | == Lesson #3: Managing files with GitHub == | ||
+ | I learned to edit my repository files locally by accessing it through the shell with [[git]]. | ||
+ | |||
+ | I had to install ''Git'' first using the ''apt-get'' command: | ||
+ | <source> | ||
+ | sudo apt-get install git | ||
+ | </source> | ||
+ | |||
+ | I made a local copy of my repo by going to the repo's page in Github at [https://github.com/Cyrusty/cy.rusty.space github.com/Cyrusty/cy.rusty.space] and then getting the ''SSH'' address of the repo from the big green ''clone or download'' button. Then I used the address in a '''git clone''' command to make a copy in my ''/var/www'' directory (which I had to change the permissions of first). | ||
+ | <source> | ||
+ | cd /var/www | ||
+ | chmod 777 /var/www | ||
+ | git clone git@github.com:Cyrusty/cy.rusty.space.git | ||
+ | </source> | ||
+ | |||
+ | I then went into the ''cy.rusty.space'' directory which is the copy of the repo it made. | ||
+ | <source> | ||
+ | cd cy.rusty.space | ||
+ | ls -al | ||
+ | </source> | ||
+ | |||
+ | I then used the ''nano'' shell editor to edit the ''README.md'' file (see [[#Lesson #1: Setting up the essentials for my server|Lesson #1]] for how to use ''nano''). | ||
+ | |||
+ | After making any changes I would commit the changes using the '''git commit''' as follows: | ||
+ | <source> | ||
+ | git commit -am "Describe whatever changes I made etc" | ||
+ | </source> | ||
+ | '''Note''' that you generally do a commit for each different task after you've got it working properly or looking right etc. | ||
+ | |||
+ | Committing changes doesn't need the server, it's all on my local copy only, after I've made a bunch of commits, I can then ''push'' then to the main repo on the server. I can make changes locally without the need of the internet but to do the git push I need access to the internet. | ||
+ | <source> | ||
+ | git push | ||
+ | </source> | ||
+ | |||
+ | Aran made some more changes to the main repo which I could pull down to my local copy as follows: | ||
+ | <source> | ||
+ | git pull | ||
+ | </source> | ||
+ | I need to '''git pull''' before making edits because the repo may have changed since it was worked on last. Generally the idea is that when you're about to do some work on a project, you do the following work-flow: | ||
+ | # '''git pull''' to make sure you're all up to date | ||
+ | # Do some changes to the files and '''git commit''' them | ||
+ | # Do some more changes to the files and '''git commit''' them | ||
+ | # '''git push''' to update the repo | ||
+ | '''Note''' that you might want to pull and push more often if you know that other people are also working on the project at the same time. You'll be notified by email when things change in repos you have ''commit'' access to. | ||
+ | |||
+ | We then went to the repo at [https://github.com/Cyrusty/cy.rusty.space github.com/Cyrusty/cy.rusty.space] and saw that the changes we'd made had been pushed properly to GitHub's copy of the repo. By clicking on [https://github.com/Cyrusty/cy.rusty.space/commits/master commits] I can see all the history of changes that have been made, and then I can click on one of the ID links to the right of the commits, such as [https://github.com/Cyrusty/cy.rusty.space/commit/46164154b7cc8cb9aca9dde67643ccbd97b9ba39 4616415], to see exactly what was changed in any of the commits. | ||
+ | |||
+ | |||
+ | To reset a git file back to a previous time if your not happy with the changes someone or yourself have made then I can do this by typing in | ||
+ | <source> | ||
+ | git reset --hard [ID of file] | ||
+ | </source> | ||
+ | |||
+ | |||
+ | An important thing to understand is that ''git'' is [[peer-to-peer]], your copy of the repo, and my copy and even the copy at Github are all identical, if GitHub suddenly disappeared you haven't lost anything because all the code and history of changes are in your local copy of the repo. The only reason we use GitHub is because they have a cool site that makes it easier to work with our files, and because it's a massive community that makes it easy for people to find your project. |
Revision as of 07:37, 28 April 2018
Lesson #2: Setting up a GitHub account
I have now created an account on GitHub which a web application allowing people and teams to work on their code and record all the changes made to it. My GitHub profile is at github.com/Cyrusty. I then created a repository for the code that will make up my site, my new repository is at github.com/Cyrusty/cy.rusty.space.
I also added in my public RSA key by going into the shell on my local computer and printing the contents out with the following command:
cat .ssh/id_rsa.pub
This printed out my public key which is shown below. It's no problem for me to show it here because it's public, people who have my public key can use it to encrypt or lock things so that only I can access them.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6gxSQCs9A5645IhmIJMnE/WxLEgqDTASj
/YloaV0fI4/b3S3APQ/UqkejZxtH7ctJrRKxD3gQ3HwXZPzmiCLOUw2Pji1BOIP/5gSB1cpD4ewK3
/3+pIrkqo3zL5u8eE6oVjdkk8GZJTF05E4LSy0vfr0D2eCsKdXMmCoz+eA83Cbnv6Pkbn4RW1SLUEhl
N8DQRYMpzJML1P8WfiZabEDxvLRejClFZpN+J74Znkov6lg47cqLZCSYZOmopcq9abIq1EeJnG3Kw0
/JDb8QyL9NFdoEa6MbfPbouTpQ2If3ZIE238SGR2FB4qxBFxKY0Tz4hFlr+3tBqnQPKLWDmWnh cyrusty@cyrusty
I could then select it, copy it and paste it into the text-box in GitHub's page for add a new key.
Lesson #3: Managing files with GitHub
I learned to edit my repository files locally by accessing it through the shell with git.
I had to install Git first using the apt-get command:
sudo apt-get install git
I made a local copy of my repo by going to the repo's page in Github at github.com/Cyrusty/cy.rusty.space and then getting the SSH address of the repo from the big green clone or download button. Then I used the address in a git clone command to make a copy in my /var/www directory (which I had to change the permissions of first).
cd /var/www
chmod 777 /var/www
git clone git@github.com:Cyrusty/cy.rusty.space.git
I then went into the cy.rusty.space directory which is the copy of the repo it made.
cd cy.rusty.space
ls -al
I then used the nano shell editor to edit the README.md file (see Lesson #1 for how to use nano).
After making any changes I would commit the changes using the git commit as follows:
git commit -am "Describe whatever changes I made etc"
Note that you generally do a commit for each different task after you've got it working properly or looking right etc.
Committing changes doesn't need the server, it's all on my local copy only, after I've made a bunch of commits, I can then push then to the main repo on the server. I can make changes locally without the need of the internet but to do the git push I need access to the internet.
git push
Aran made some more changes to the main repo which I could pull down to my local copy as follows:
git pull
I need to git pull before making edits because the repo may have changed since it was worked on last. Generally the idea is that when you're about to do some work on a project, you do the following work-flow:
- git pull to make sure you're all up to date
- Do some changes to the files and git commit them
- Do some more changes to the files and git commit them
- git push to update the repo
Note that you might want to pull and push more often if you know that other people are also working on the project at the same time. You'll be notified by email when things change in repos you have commit access to.
We then went to the repo at github.com/Cyrusty/cy.rusty.space and saw that the changes we'd made had been pushed properly to GitHub's copy of the repo. By clicking on commits I can see all the history of changes that have been made, and then I can click on one of the ID links to the right of the commits, such as 4616415, to see exactly what was changed in any of the commits.
To reset a git file back to a previous time if your not happy with the changes someone or yourself have made then I can do this by typing in
git reset --hard [ID of file]
An important thing to understand is that git is peer-to-peer, your copy of the repo, and my copy and even the copy at Github are all identical, if GitHub suddenly disappeared you haven't lost anything because all the code and history of changes are in your local copy of the repo. The only reason we use GitHub is because they have a cool site that makes it easier to work with our files, and because it's a massive community that makes it easy for people to find your project.