Difference between revisions of "GitHub"
Adelo Vieira (talk | contribs) (→Basics about creating, committing and pushing a repository) |
Adelo Vieira (talk | contribs) (→Another Collaborative and Remote development resources I have been testing) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 50: | Line 50: | ||
=='''Basics about creating, committing and pushing a repository'''== | =='''Basics about creating, committing and pushing a repository'''== | ||
+ | <br /> | ||
* '''Create a repository on https://github.com:''' | * '''Create a repository on https://github.com:''' | ||
<blockquote> | <blockquote> | ||
Line 293: | Line 294: | ||
Websites for you and your projects. Hosted directly from your GitHub repository. Just edit, push, and your changes are live. | 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: | ||
+ | * This is the repository: https://github.com/adeloaleman/adeloaleman.github.io | ||
+ | * You can access the page at https://adeloaleman.github.io | ||
<br /> | <br /> | ||
+ | |||
==Another Collaborative and Remote development resources I have been testing== | ==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 | + | This is not related to GitHub at all. I'm leaving this section here cause I haven't found a better place for it. |
Latest revision as of 19:16, 5 May 2023
Contents
- 1 Installing Git
- 2 Configuring GitHub
- 3 GUI Clients - Github Desktop
- 4 Basics about creating, committing and pushing a repository
- 5 Ignnore - exclure files when commiting or pushing
- 6 My uptoday script
- 7 How to change the URL for a remote Git repository
- 8 Git push requires username and password
- 9 GitHub Pages
- 10 Another Collaborative and Remote development resources I have been testing
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:
- https://git-scm.com/download/gui/linux
- He instalado ésta: https://www.gitkraken.com/
Github Desktop
Basics about creating, committing and pushing a repository
- Create a repository on https://github.com:
- 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
- If it's a new and empty repository on https://github.com:
# 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
- If there is already files into the repository on https://github.com:
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
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:
- This is the repository: https://github.com/adeloaleman/adeloaleman.github.io
- You can access the page at https://adeloaleman.github.io
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://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