Difference between revisions of "GitHub"

From Sinfronteras
Jump to: navigation, search
(Created page with "==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...")
 
(Another Collaborative and Remote development resources I have been testing)
 
(20 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 />
 +
* '''Create a local repository in our computer:'''
 +
<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
 +
 
 +
 
 +
# Create the repository
 +
git init
 +
git remote add origin https://github.com/adeloaleman/ProyectoPiloto.git
 +
</syntaxhighlight>
 +
 
 +
</blockquote>
 +
 
 +
 
 +
<br />
 +
* '''If it's a new and empty repository on https://github.com:'''
 +
<blockquote>
 +
 
 +
<syntaxhighlight lang="shell">
 +
# 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
 +
</syntaxhighlight>
 +
 
 +
</blockquote>
 +
 
 +
 
 +
<br />
 +
* '''If there is already files into the repository  on 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 />
 +
'''Tenemos dos opciones:'''
 +
<blockquote>
 +
 
 +
 
 +
<br />
 +
'''1. To clone the repository:'''
 +
<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
 +
 
 +
 
 +
# Or using ssh:
 +
git clone git@github.com:adeloaleman/ProyectoPiloto.git
 +
</syntaxhighlight>
 +
 
 +
</blockquote>
 +
 
 +
 
 +
<br />
 +
'''2. Forzar el «push» a través de la opción «-f»:'''
 +
<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 />
 +
* '''Si nuestro repositorio contiene Branches'''
 +
<blockquote>
 +
 
 +
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:
 +
<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 />
 +
 
 +
==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.
 +
 
  
==Mount a remote filesystem in your local machine==
+
My basic «.gitignore» looks like this:
https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh
+
<syntaxhighlight lang="shell">
 +
.gitignore
 +
.uptoday.sh
 +
</syntaxhighlight>
  
https://stackoverflow.com/questions/32747819/remote-java-development-using-intellij-or-eclipse
 
  
https://serverfault.com/questions/306796/sshfs-problem-when-losing-connection
+
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.
  
https://askubuntu.com/questions/358906/sshfs-messes-up-everything-if-i-lose-connection
 
  
https://askubuntu.com/questions/716612/sshfs-auto-reconnect
+
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
  
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
+
### 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>
  
sshfs -o allow_other root@sinfronteras.ws: /home/adelo/1-system/3-cloud
 
  
 +
<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:
  
'''faster way to mount a remote file system than sshfs:'''
+
<syntaxhighlight lang="shell">
https://superuser.com/questions/344255/faster-way-to-mount-a-remote-file-system-than-sshfs
+
git rm --cached .uptoday.sh
 +
</syntaxhighlight>
  
==Git and GitHub==
+
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.
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===
+
<br />
https://www.howtoforge.com/tutorial/install-git-and-github-on-ubuntu/
+
==My uptoday script==
 +
I have also created a «.uptoday.sh» script to automate the pushing process.
  
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.
+
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:
  
  git config --global user.name "user_name"
+
  ./.uptoday.sh                        # This will commit and push the changes using the «commit comment»: "commit"
  git config --global user.email "email_id"
+
  ./.uptoday.sh "The navbar was added"  # This will commit and push the changes using the «commit comment»: "The navbar was added"
  
git config --global user.name "adeloaleman"
 
git config --global user.email "adeloaleman@gmail.com"
 
  
===Creating a local repository===
+
.uptoday.sh
git init /home/adelo/1-system/1-disco_local/1-mis_archivos/1-pe/1-ciencia/1-computacion/1-programacion/GitHubLocalRepository
+
<syntaxhighlight lang="shell">
 +
#! /bin/sh
  
===Creating a README file to describe the repository===
+
git add .
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:
 
  
vi README
+
commit="$1"
This is Adelo's git repo
 
  
===Adding repository files to an index===
+
if [ -z "$commit" ]
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).
+
then
 +
git commit -m "commit"
 +
# echo "Please set \$commit"
  
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:
+
else
 +
git commit -m "$1"
 +
# echo "Setting up jail at $commit"
 +
fi
  
vi sample.c
+
git push -u origin master
<syntaxhighlight lang="C">
 
#include<stdio.h>
 
int main()
 
{
 
    printf("hello world");
 
    return 0;
 
}
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
So, now that we have 2 files:
 
README and sample.c
 
  
add it to the index by using the following 2 commands:
+
<br />
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.
+
==How to change the URL for a remote Git repository==
 +
https://help.github.com/en/github/using-git/changing-a-remotes-url
  
===Committing changes made to the index===
 
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:
 
git commit -m "some_message"
 
  
"some_message" in the above command can be any simple message like "my first commit" or "edit in readme", etc.
+
git remote set-url origin https://github.com/adeloaleman/JavaDesktopApp-ZooManagementSystem.git
  
===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:
+
<br />
git remote add origin https://github.com/adeloaleman/GitHubLocalRepository
+
==Git push requires username and password==
 +
https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password
  
===Pushing files in local repository to GitHub repository===
+
In the link above there is apparently an explanation about how to avoid typing the username and password every time you push files.
The final step is to push the local repository contents into the remote host repository (GitHub), by using the command:
 
git push origin master
 
  
===GUI Clients===
 
Git comes with built-in GUI tools for committing (git-gui) and browsing (gitk), but there are several third-party tools for users looking for platform-specific experience.
 
  
https://desktop.github.com/
+
<br />
 +
==GitHub Pages==
 +
https://pages.github.com/
  
Parece que la aplicación oficial GitHub Desktop no está disponible para Ubuntu. Entonces hay otras aplicaciones similares disponibles para Linux:
+
Websites for you and your projects. Hosted directly from your GitHub repository. Just edit, push, and your changes are live.
https://git-scm.com/download/gui/linux
+
 
 +
 
 +
I have done an example:
 +
* This is the repository: https://github.com/adeloaleman/adeloaleman.github.io
 +
* You can access the page at https://adeloaleman.github.io
 +
 
 +
 
 +
<br />
 +
 
 +
==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 />
 +
===Eclipse - Connect to a remote file system===
 +
https://us.informatiweb.net/tutorials/it/6-web/148--eclipse-connect-to-a-remote-file-system.html
 +
 
 +
 
 +
<br />
 +
===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
  
  
He instalado ésta: https://www.gitkraken.com/
+
<br />

Latest revision as of 20: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