Difference between revisions of "GitHub"

From Sinfronteras
Jump to: navigation, search
(Another Collaborative and Remote development resources I have been testing)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Eclipse - Connect to a remote file system==
+
https://github.com
https://us.informatiweb.net/tutorials/it/6-web/148--eclipse-connect-to-a-remote-file-system.html
+
 
 +
 
 +
<br />
 +
==Installing Git==
 +
https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04
 +
 +
sudo apt install git
 +
 
 +
 
 +
<br />
 +
==Configuring GitHub==
 +
https://www.howtoforge.com/tutorial/install-git-and-github-on-ubuntu/
 +
 
 +
We need to set up the configuration details of the GitHub user. To do this use the following two commands by replacing "user_name" with your GitHub username and replacing "email_id" with your email-id you used to create your GitHub account.
 +
 
 +
git config --global user.name "user_name"
 +
git config --global user.email "email_id"
 +
 
 +
git config --global user.name "adeloaleman"
 +
git config --global user.email "adeloaleman@gmail.com"
 +
 
 +
 
 +
<br />
 +
==GUI Clients - Github Desktop==
 +
Git comes with built-in GUI tools for committing (git-gui) and browsing (gitk), but there are several Desktop tools for users looking for platform-specific experience:
 +
 
 +
* '''GitHub Desktop (aplicación oficial GitHub):'''
 +
:* https://snapcraft.io/github-desktop
 +
:* https://desktop.github.com/
 +
 
 +
 
 +
Hay otras aplicaciones similares a la aplicación oficial GitHub Desktop disponibles para Linux:
 +
* https://git-scm.com/download/gui/linux
 +
* He instalado ésta: https://www.gitkraken.com/
 +
 
 +
 
 +
<br />
 +
===Github Desktop===
 +
* https://snapcraft.io/github-desktop
 +
* https://desktop.github.com/release-notes/
 +
 
 +
 
 +
<br />
 +
====Install GitHub Desktop on Ubuntu====
 +
https://snapcraft.io/install/github-desktop/ubuntu
 +
 
 +
 
 +
<br />
 +
=='''Basics about creating, committing and pushing a repository'''==
 +
 
 +
<br />
 +
* '''Create a repository on https://github.com:'''
 +
<blockquote>
 +
* Go to https://github.com and click on «New»
 +
* Repository name: WebApp-CloneOfTwitter
 +
* ...
 +
* Click «Create repository»
 +
</blockquote>
  
  
 
<br />
 
<br />
==Mount a remote filesystem in your local machine==
+
* '''Create a local repository in our computer:'''
https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh
+
<blockquote>
 +
 
 +
After we create a repository at https://github.com, we have to create a local repository in our computer:
 +
 
 +
<syntaxhighlight lang="shell">
 +
mkdir nombreDelRepositorio
 +
cd nombreDelRepositorio
  
https://stackoverflow.com/questions/32747819/remote-java-development-using-intellij-or-eclipse
 
  
https://serverfault.com/questions/306796/sshfs-problem-when-losing-connection
+
# Create the repository
 +
git init
 +
git remote add origin https://github.com/adeloaleman/ProyectoPiloto.git
 +
</syntaxhighlight>
  
https://askubuntu.com/questions/358906/sshfs-messes-up-everything-if-i-lose-connection
+
</blockquote>
  
https://askubuntu.com/questions/716612/sshfs-auto-reconnect
 
  
root@sinfronteras.ws: /home/adelo/1-system/3-cloud
+
<br />
 +
* '''If it's a new and empty repository on https://github.com:'''
 +
<blockquote>
  
sshfs -o reconnect,ServerAliveInterval=5,ServerAliveCountMax=3 root@sinfronteras.ws: /home/adelo/1-system/3-cloud
+
<syntaxhighlight lang="shell">
 +
# In case we want to create a RAADME file
 +
echo "# ProyectoPiloto" >> README.md
  
sshfs -o allow_other root@sinfronteras.ws: /home/adelo/1-system/3-cloud
 
  
 +
# Commit and push the files
 +
git add .
 +
git commit -m "first commit"
 +
git push -u origin master
 +
</syntaxhighlight>
  
'''faster way to mount a remote file system than sshfs:'''
+
</blockquote>
https://superuser.com/questions/344255/faster-way-to-mount-a-remote-file-system-than-sshfs
 
  
  
 
<br />
 
<br />
==Git and GitHub==
+
* '''If there is already files into the repository  on https://github.com:'''
https://github.com/
+
<blockquote>
 +
 
 +
Ahora, si queremos crear un repository local in our computer para un repository en https://github.com que ya contiene archivos, al intentar «git push -u origin master» obtendremos el siguiente error:
 +
 
 +
<syntaxhighlight lang="shell">
 +
error: failed to push some refs to 'https://github.com/adeloaleman/gofaaas.git'
 +
hint: Updates were rejected because the remote contains work that you do
 +
hint: not have locally. This is usually caused by another repository pushing
 +
hint: to the same ref. You may want to first integrate the remote changes
 +
hint: (e.g., 'git pull ...') before pushing again.
 +
</syntaxhighlight>
  
  
 
<br />
 
<br />
===Installing Git===
+
'''Tenemos dos opciones:'''
https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04
+
<blockquote>
 
sudo apt install git
 
  
  
 
<br />
 
<br />
===Configuring GitHub===
+
'''1. To clone the repository:'''
https://www.howtoforge.com/tutorial/install-git-and-github-on-ubuntu/
+
<blockquote>
 +
 
 +
Si queremos preservar los archivos que se encuentran en el repositorio en https://github.com
 +
 
 +
https://confluence.atlassian.com/bitbucket/clone-a-repository-223217891.html
 +
 
 +
 
 +
<syntaxhighlight lang="shell">
 +
git clone https://github.com/adeloaleman/ProyectoPiloto.git
  
We need to set up the configuration details of the GitHub user. To do this use the following two commands by replacing "user_name" with your GitHub username and replacing "email_id" with your email-id you used to create your GitHub account.
 
  
git config --global user.name "user_name"
+
# Or using ssh:
git config --global user.email "email_id"
+
git clone git@github.com:adeloaleman/ProyectoPiloto.git
 +
</syntaxhighlight>
  
git config --global user.name "adeloaleman"
+
</blockquote>
git config --global user.email "adeloaleman@gmail.com"
 
  
  
 
<br />
 
<br />
===Creating a local repository===
+
'''2. Forzar el «push» a través de la opción «-f»:'''
git init /home/adelo/1-system/1-disco_local/1-mis_archivos/1-pe/1-ciencia/1-computacion/1-programacion/GitHubLocalRepository
+
<blockquote>
 +
 
 +
Los archivo que se encuentran en https://github.com serán reemplazados.
 +
 
 +
 
 +
<syntaxhighlight lang="shell">
 +
git push -f origin master
 +
</syntaxhighlight>
 +
 
 +
</blockquote>
 +
</blockquote>
 +
</blockquote>
  
  
 
<br />
 
<br />
===Creating a README file to describe the repository===
+
* '''Si nuestro repositorio contiene Branches'''
Now create a README file and enter some text like "this is a git setup on Linux". The README file is generally used to describe what the repository contains or what the project is all about. Example:
+
<blockquote>
  
vi README
+
En este caso no podremos realizar «commit» and «push» al «master». Tenemos que trabajar en nuestro branch y hacer el «commit» and «push» hacia nuestro branch.
This is Adelo's git repo
+
 
 +
 
 +
Entonces, desde nuestro repositorio local en nuestra computadora, podemos cambiar de branch de la siguiente forma:
 +
<syntaxhighlight lang="shell">
 +
git checkout «branch_name»
 +
git checkout adelo
 +
</syntaxhighlight>
 +
 
 +
 
 +
Luego los «commit» and «push» se deben realizar de la siguiente forma:
 +
<syntaxhighlight lang="shell">
 +
git push -u origin adelo
 +
</syntaxhighlight>
 +
 
 +
</blockquote>
  
  
 
<br />
 
<br />
===Adding repository files to an index===
 
This is an important step. Here we add all the things that need to be pushed onto the website into an index. These things might be the text files or programs that you might add for the first time into the repository or it could be adding a file that already exists but with some changes (a newer version/updated version).
 
  
Here we already have the README file. So, let's create another file which contains a simple C program and call it sample.c. The contents of it will be:
+
==Ignnore - exclure files when commiting or pushing==
 +
https://www.atlassian.com/git/tutorials/saving-changes/gitignore
  
vi sample.c
+
Debemos crear el file '''«.gitignore»'''
<syntaxhighlight lang="C">
+
 
#include<stdio.h>
+
Al parecer, se puede crear en el home y puede ser utilizado para excluir files en cualquier repositorio. Yo lo he sin embargo creado en el current repository. En este file simplemente tenemos que escribir los files que queremos excluir.
int main()
+
 
{
+
 
    printf("hello world");
+
My basic «.gitignore» looks like this:
    return 0;
+
<syntaxhighlight lang="shell">
}
+
.gitignore
 +
.uptoday.sh
 
</syntaxhighlight>
 
</syntaxhighlight>
  
So, now that we have 2 files:
 
README and sample.c
 
  
add it to the index by using the following 2 commands:
+
However, there can be many different files depending on the project. Actually, Githup will propose you a «.gitignore» file when you create a repository based on the Language, Framework or Library.
git add README
 
git add smaple.c
 
  
Note that the "git add" command can be used to add any number of files and folders to the index. Here, when I say index, what I am referring to is a buffer like space that stores the files/folders that have to be added into the Git repository.
+
 
 +
For example, for a React project, we have to exclude the «/node_modules» folder. This is how my «.gitignore» file looks like for my React project. I have actually commented the recommended exclusion files because I didn't understand well why they were being excluding. However, it can be important to exclude some of these files; sometimes for security reasons:
 +
<syntaxhighlight lang="shell">
 +
.gitignore
 +
.uptoday.sh
 +
/backEnd-express/node_modules
 +
/frontEnd-react/node_modules
 +
 
 +
 
 +
### Lo siguiente es el archivo .gitignore generado automaticamente cuando cree el proyecto React
 +
## See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
 +
#
 +
## dependencies
 +
#/node_modules
 +
#/.pnp
 +
#.pnp.js
 +
#
 +
## testing
 +
#/coverage
 +
#
 +
## production
 +
#/build
 +
#
 +
## misc
 +
#.DS_Store
 +
#.env.local
 +
#.env.development.local
 +
#.env.test.local
 +
#.env.production.local
 +
#
 +
#npm-debug.log*
 +
#yarn-debug.log*
 +
#yarn-error.log*
 +
</syntaxhighlight>
 +
 
 +
 
 +
<br />
 +
===If you want to ignore a file that you have committed in the past===
 +
For example, if we want to ignore our «.uptoday.sh» but it has already been committed in the past, you'll need to delete the file from your repository this way:
 +
 
 +
<syntaxhighlight lang="shell">
 +
git rm --cached .uptoday.sh
 +
</syntaxhighlight>
 +
 
 +
Using '''<code>git rm --cached .uptoday.sh</code>''' means that the file will be deleted from your «repository», but will remain in your «working directory» as an ignored file.
  
  
 
<br />
 
<br />
===Committing changes made to the index===
+
==My uptoday script==
Once all the files are added, we can commit it. This means that we have finalized what additions and/or changes have to be made and they are now ready to be uploaded to our repository. Use the command:
+
I have also created a «.uptoday.sh» script to automate the pushing process.
git commit -m "some_message"
+
 
 +
This script is able to optionally take an argument. If you don't give it an argument the «commit comment» will just be "commit"; but you can specify a «commit comment» in the argument of the script. For example:
  
"some_message" in the above command can be any simple message like "my first commit" or "edit in readme", etc.
+
./.uptoday.sh                        # This will commit and push the changes using the «commit comment»: "commit"
 +
./.uptoday.sh "The navbar was added" # This will commit and push the changes using the «commit comment»: "The navbar was added"
 +
 
 +
 
 +
.uptoday.sh
 +
<syntaxhighlight lang="shell">
 +
#! /bin/sh
 +
 
 +
git add .
 +
 
 +
commit="$1"
 +
 
 +
if [ -z "$commit" ]
 +
then
 +
git commit -m "commit"
 +
# echo "Please set \$commit"
 +
 
 +
else
 +
git commit -m "$1"
 +
# echo "Setting up jail at $commit"
 +
fi
 +
 
 +
git push -u origin master
 +
</syntaxhighlight>
  
  
 
<br />
 
<br />
===Creating a repository on GitHub===
 
Create a repository on GitHub. Notice that the name of the repository should be the same as the repository's on the local system. In this case, it will be "Mytest". To do this login to your account on https://github.com. Then click on the "plus(+)" symbol at the top right corner of the page and select "create new repository". Fill the details as shown in the image below and click on "create repository" button.
 
  
Once this is created, we can push the contents of the local repository onto the GitHub repository in your profile. Connect to the repository on GitHub using the command:
+
==How to change the URL for a remote Git repository==
  git remote add origin https://github.com/adeloaleman/GitHubLocalRepository
+
https://help.github.com/en/github/using-git/changing-a-remotes-url
 +
 
 +
 
 +
  git remote set-url origin https://github.com/adeloaleman/JavaDesktopApp-ZooManagementSystem.git
  
  
 
<br />
 
<br />
===Pushing files in local repository to GitHub repository===
+
==Git push requires username and password==
The final step is to push the local repository contents into the remote host repository (GitHub), by using the command:
+
https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password
git push origin master
+
 
 +
In the link above there is apparently an explanation about how to avoid typing the username and password every time you push files.
  
  
 
<br />
 
<br />
===GUI Clients - Github Desktop===
+
==GitHub Pages==
Git comes with built-in GUI tools for committing (git-gui) and browsing (gitk), but there are several Desktop tools for users looking for platform-specific experience:
+
https://pages.github.com/
 +
 
 +
Websites for you and your projects. Hosted directly from your GitHub repository. Just edit, push, and your changes are live.
 +
 
  
* '''GitHub Desktop (aplicación oficial GitHub):'''
+
I have done an example:
:* https://snapcraft.io/github-desktop
+
* This is the repository: https://github.com/adeloaleman/adeloaleman.github.io
:* https://desktop.github.com/
+
* You can access the page at https://adeloaleman.github.io
  
  
Hay otras aplicaciones similares a la aplicación oficial GitHub Desktop disponibles para Linux:
+
<br />
* https://git-scm.com/download/gui/linux
+
 
* He instalado ésta: https://www.gitkraken.com/
+
==Another Collaborative and Remote development resources I have been testing==
 +
This is not related to GitHub at all. I'm leaving this section here cause I haven't found a better place for it.
  
  
 
<br />
 
<br />
====Github Desktop====
+
===Eclipse - Connect to a remote file system===
* https://snapcraft.io/github-desktop
+
https://us.informatiweb.net/tutorials/it/6-web/148--eclipse-connect-to-a-remote-file-system.html
* https://desktop.github.com/release-notes/
 
  
  
 
<br />
 
<br />
=====Install GitHub Desktop on Ubuntu=====
+
===Mount a remote filesystem in your local machine===
https://snapcraft.io/install/github-desktop/ubuntu
+
https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh
 +
 
 +
https://stackoverflow.com/questions/32747819/remote-java-development-using-intellij-or-eclipse
 +
 
 +
https://serverfault.com/questions/306796/sshfs-problem-when-losing-connection
 +
 
 +
https://askubuntu.com/questions/358906/sshfs-messes-up-everything-if-i-lose-connection
 +
 
 +
https://askubuntu.com/questions/716612/sshfs-auto-reconnect
 +
 
 +
root@sinfronteras.ws: /home/adelo/1-system/3-cloud
 +
 
 +
sshfs -o reconnect,ServerAliveInterval=5,ServerAliveCountMax=3 root@sinfronteras.ws: /home/adelo/1-system/3-cloud
 +
 
 +
sshfs -o allow_other root@sinfronteras.ws: /home/adelo/1-system/3-cloud
 +
 
 +
 
 +
'''faster way to mount a remote file system than sshfs:'''
 +
https://superuser.com/questions/344255/faster-way-to-mount-a-remote-file-system-than-sshfs
  
  
 
<br />
 
<br />

Latest revision as of 19:16, 5 May 2023

https://github.com



Installing Git

https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04

sudo apt install git



Configuring GitHub

https://www.howtoforge.com/tutorial/install-git-and-github-on-ubuntu/

We need to set up the configuration details of the GitHub user. To do this use the following two commands by replacing "user_name" with your GitHub username and replacing "email_id" with your email-id you used to create your GitHub account.

git config --global user.name "user_name"
git config --global user.email "email_id"
git config --global user.name "adeloaleman"
git config --global user.email "adeloaleman@gmail.com"



GUI Clients - Github Desktop

Git comes with built-in GUI tools for committing (git-gui) and browsing (gitk), but there are several Desktop tools for users looking for platform-specific experience:

  • GitHub Desktop (aplicación oficial GitHub):


Hay otras aplicaciones similares a la aplicación oficial GitHub Desktop disponibles para Linux:



Github Desktop



Install GitHub Desktop on Ubuntu

https://snapcraft.io/install/github-desktop/ubuntu



Basics about creating, committing and pushing a repository


  • Go to https://github.com and click on «New»
  • Repository name: WebApp-CloneOfTwitter
  • ...
  • Click «Create repository»



  • Create a local repository in our computer:

After we create a repository at https://github.com, we have to create a local repository in our computer:

mkdir nombreDelRepositorio
cd nombreDelRepositorio


# Create the repository
git init
git remote add origin https://github.com/adeloaleman/ProyectoPiloto.git



# In case we want to create a RAADME file
echo "# ProyectoPiloto" >> README.md


# Commit and push the files
git add .
git commit -m "first commit"
git push -u origin master



Ahora, si queremos crear un repository local in our computer para un repository en https://github.com que ya contiene archivos, al intentar «git push -u origin master» obtendremos el siguiente error:

error: failed to push some refs to 'https://github.com/adeloaleman/gofaaas.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.



Tenemos dos opciones:



1. To clone the repository:

Si queremos preservar los archivos que se encuentran en el repositorio en https://github.com

https://confluence.atlassian.com/bitbucket/clone-a-repository-223217891.html


git clone https://github.com/adeloaleman/ProyectoPiloto.git


# Or using ssh:
git clone git@github.com:adeloaleman/ProyectoPiloto.git



2. Forzar el «push» a través de la opción «-f»:

Los archivo que se encuentran en https://github.com serán reemplazados.


git push -f origin master



  • Si nuestro repositorio contiene Branches

En este caso no podremos realizar «commit» and «push» al «master». Tenemos que trabajar en nuestro branch y hacer el «commit» and «push» hacia nuestro branch.


Entonces, desde nuestro repositorio local en nuestra computadora, podemos cambiar de branch de la siguiente forma:

git checkout «branch_name»
git checkout adelo


Luego los «commit» and «push» se deben realizar de la siguiente forma:

git push -u origin adelo



Ignnore - exclure files when commiting or pushing

https://www.atlassian.com/git/tutorials/saving-changes/gitignore

Debemos crear el file «.gitignore»

Al parecer, se puede crear en el home y puede ser utilizado para excluir files en cualquier repositorio. Yo lo he sin embargo creado en el current repository. En este file simplemente tenemos que escribir los files que queremos excluir.


My basic «.gitignore» looks like this:

.gitignore
.uptoday.sh


However, there can be many different files depending on the project. Actually, Githup will propose you a «.gitignore» file when you create a repository based on the Language, Framework or Library.


For example, for a React project, we have to exclude the «/node_modules» folder. This is how my «.gitignore» file looks like for my React project. I have actually commented the recommended exclusion files because I didn't understand well why they were being excluding. However, it can be important to exclude some of these files; sometimes for security reasons:

.gitignore
.uptoday.sh
/backEnd-express/node_modules
/frontEnd-react/node_modules


### Lo siguiente es el archivo .gitignore generado automaticamente cuando cree el proyecto React
## See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
#
## dependencies
#/node_modules
#/.pnp
#.pnp.js
#
## testing
#/coverage
#
## production
#/build
#
## misc
#.DS_Store
#.env.local
#.env.development.local
#.env.test.local
#.env.production.local
#
#npm-debug.log*
#yarn-debug.log*
#yarn-error.log*



If you want to ignore a file that you have committed in the past

For example, if we want to ignore our «.uptoday.sh» but it has already been committed in the past, you'll need to delete the file from your repository this way:

git rm --cached .uptoday.sh

Using git rm --cached .uptoday.sh means that the file will be deleted from your «repository», but will remain in your «working directory» as an ignored file.



My uptoday script

I have also created a «.uptoday.sh» script to automate the pushing process.

This script is able to optionally take an argument. If you don't give it an argument the «commit comment» will just be "commit"; but you can specify a «commit comment» in the argument of the script. For example:

./.uptoday.sh                         # This will commit and push the changes using the «commit comment»: "commit"
./.uptoday.sh "The navbar was added"  # This will commit and push the changes using the «commit comment»: "The navbar was added"


.uptoday.sh
#! /bin/sh

git add .

commit="$1"

if [ -z "$commit" ]
then
	git commit -m "commit"
	# echo "Please set \$commit"

else
	git commit -m "$1"
	# echo "Setting up jail at $commit"
fi

git push -u origin master



How to change the URL for a remote Git repository

https://help.github.com/en/github/using-git/changing-a-remotes-url


git remote set-url origin https://github.com/adeloaleman/JavaDesktopApp-ZooManagementSystem.git



Git push requires username and password

https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password

In the link above there is apparently an explanation about how to avoid typing the username and password every time you push files.



GitHub Pages

https://pages.github.com/

Websites for you and your projects. Hosted directly from your GitHub repository. Just edit, push, and your changes are live.


I have done an example:



Another Collaborative and Remote development resources I have been testing

This is not related to GitHub at all. I'm leaving this section here cause I haven't found a better place for it.



Eclipse - Connect to a remote file system

https://us.informatiweb.net/tutorials/it/6-web/148--eclipse-connect-to-a-remote-file-system.html



Mount a remote filesystem in your local machine

https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh

https://stackoverflow.com/questions/32747819/remote-java-development-using-intellij-or-eclipse

https://serverfault.com/questions/306796/sshfs-problem-when-losing-connection

https://askubuntu.com/questions/358906/sshfs-messes-up-everything-if-i-lose-connection

https://askubuntu.com/questions/716612/sshfs-auto-reconnect

root@sinfronteras.ws: /home/adelo/1-system/3-cloud
sshfs -o reconnect,ServerAliveInterval=5,ServerAliveCountMax=3 root@sinfronteras.ws: /home/adelo/1-system/3-cloud
sshfs -o allow_other root@sinfronteras.ws: /home/adelo/1-system/3-cloud


faster way to mount a remote file system than sshfs: https://superuser.com/questions/344255/faster-way-to-mount-a-remote-file-system-than-sshfs