You are on page 1of 4

GIT COMMANDS TUTORIALS

*Initialize git
git init

*When it is the first time git is connected we need to set:


git remote add origin https://gloton.ugr.es/gitlab/mpedrosab/wos_api.git
*Clone repository
git clone https://external-host.com/extuser/repo.git

*Clone single branch


git clone --single-branch --branch <branchname> host:/dir.git

*Push locally cloned repository with mirror option


cd repo.git
git push --mirror https://github.com/ghuser/repo.git

or git push origin [name_of_the_branch] #despues de git add .

*Remove local repository


cd ..
rm -rf repo.git

*Remove branch

git branch -d [name_of_the_branch]


*Undo all commands
git reset

*Add local folder to Gitlab


https://www.linuxhelp.com/how-to-add-local-folder-to-a-gitlab-project
Need to run "git pull --allow-unrelated-histories" before pushing

*Add files
git add . # Run it
after adding the files to the local directory
git commit -m "First commit" # Commits the tracked
changes and prepares them to be pushed to a remote repository
git remote add origin remote <repository URL> # Sets the new remote
git remote -v # Verifies
the new remote URL
git push origin master # Pushes the
changes in your local repository up to the remote repository you specified as the
origin

NOTE: if we want to push to specific branch, change branch with "git checkout
mybranch"

*Get only specific files


git fetch
git checkout origin/main -- myfile

*Commit changes of your local directory to GitHub

*Undo add
git reset
*Create branch
git checkout -b [name_of_your_new_branch] #Create the branch on your local
machine and switch in this branch
git push origin [name_of_your_new_branch] #Push the branch on github

*Upload branch without overwriting mine (full procedure by Cristina)


git init (si no tengo el git ahi todavia)
git remote add origin <path>
git stash
git pull
git stash pop
git add .
git commit -m "lo q me salga del chumino"
git push origin master
#git stash saves my changes to a temporary location
#git stash pop can yield some problems
#if you want to use another branch do "git checkout mybranch" after pull? and
change "git push origin mybranch"

*To view the branches in a Git repository, run the command:


git branch

*To view both remote-tracking branches and local branches, run the command:
git branch -a

* Put branch up to date with master


git checkout mybranch
git fetch
git rebase origin/master

*Avoid unrelated histories warning


add --allow-unrelated-histories at the end of the command. Ex:
git pull origin master --allow-unrelated-histories

*Pull only a specific files


git fetch // git fetch will download all
the recent changes, but it will not put it in your current checked out code
(working area).
git checkout origin/master -- path/to/file // git checkout <local repo name
(default is origin)>/<branch name> -- path/to/file will checkout the particular
file from the downloaded changes (origin/master)

*make a branch to follow another remote branch


$ git branch --set-upstream-to=origin/master

*push force
git push --force

*stop merging
git merge --abort

*Reemplace all files in branch with the files from branch remote/branch
git reset --hard remote/branch

*Push and Pull


Push => from local to live DB
Pull => from DB to local

git fetch => descarga commits, archivos y referencias de un repositorio


remoto a tu repositorio local
Git aísla el contenido recuperado del contenido local existente sin tener
ningún tipo de repercusión sobre el desarrollo local de tu trabajo. El contenido
recuperado debe extraerse específicamente con el comando git checkout

When we use the push function, we are handing…the task of migrating the
database to the origin site.…The origin site literally pushes the database…to the
target site.…This is what you would use any time you are moving…a database from a
local host environment…to a live environment on the web,…meaning any time the
database sits on a server…that may not be accessible from the target site.…

You can also use the push function from one live site…on the web to another.…
The only think you can't do is push a database…from a live site on the web to a
site that's…hosted either locally on a computer,…or locally within a network the
web does not…have access to.…With pull, the target site does all the work.…In this
case, the target goes to the origin site…

***************
Computational Methods Class
git clone "link" => linkea el github
git status => te dice lo que hay

IGNORAR ARCHIVOS
Hacer fichero:
vi .gitignore
Escribir dentro el nombre de las carpetas que no queires clonar "ej: carpetafea/"

SUBIR CAMBIOS
git commit
git push

SUBIR O BAJAR SOLO ALGUNOS CAMBIOS


git cherry-peak
MEZCLAR CAMBIOS
git merge

Alternativa mejor: usar la herramienta meld.


Cuando entras en conflicto se lanza y te muestra los cambios que hay en ambos
OJO: primero hay que hacer merge desde línea de comando

Para evitar eso


* Trabajar en ramas distintas.
* Hacer git fenche para traer los datos antes de trabajar.
* Trabajar en repositorios diferentes con folk.

PONER AL DIA UN FORK

git remote add name MainRepo.git : join my computer to principal repository


git remote -v : shows remotes I am connected to
git reset --all: Put in my compùter the main repository

Now do git push myforkedrepo to my forked repository

----------- fork --------------


| main repo | --------------------------->| forked repo |
----------- -----------\ --------------
^ ^ \ ^
| \ \ |
| \ \ |
| \ \ remote add name |
| \ \ MainRepo.git |
| \ \ |
| \ pull \ |
| \ request \ |
| \ \ |
| \ \ |
v \ \ -----v v
----------- \ -----------
| owner's | \ ---------------- | my |
| computer | | computer |
----------- -----------

GUARDAR CAMBIOS TEMPORALES


git stash

DIFERENCIAS FETCH, PULL, MERGE


fetch: dime las novedades
merge: méteme las novedades remotas en mi rama. Puede especificar qué rama o que
commit en concreto mergear
pull: dime las novedades y mergéalas

You might also like