GIT

Basic

  • clone a repository
git clone [link] [repo_name]
  • set another remote repository (push on both repository simultanously with git push)
git remote set-url --add --push origin
  • show file status
git status
  • add the repo/file - you can put as many as you want
git add [repo/file]
  • commit the changes
git commit
-m: add a message
--amend: modify the last commit message
  • push the changes
git push
  • get the latest version of file uploaded to git
git pull

Move

  • move the pointer to another location
git checkout
[repo/file]: discard changes to the repo/file (stay as it was in the last commit)
[commit id]: go back to the version of the commit
[branch]: go to that branch

git reset will roll back modifications in the server

git reset [flag] [commit]
2. --hard: git reset will also roll back modif on local
1. HEAD: last commit (n)
2. HEAD^: previous commit (n - 1)
3. HEAD^^: previous commit (n - 2)
4. HEAD~x: previous commit (n - x)
5. COMMIT_NUMBER: corresponding commit

Information

  • show logs
git log
-p: to see more details
  • show differences
git diff
  • show the url of the repo host
git remote --v

Branches

  • list branchs
git branch [flag] [name]
[name]: create a branch with the corresponding name
-d [name]: delete the branch
  • saves changes on branch
git stash [branch]
if we go back to another branch, changes will be lost if not push
git stash will "save" them so we can checkout elsewhere and then come back
it's used when you don't want to commit on branch test but need to go elsewhere
with branch name, it recover changes
  • merge branchs
git merge
go in the branch where you merge (git checkout master)
merge the branch you want to (git merge test)

Submodules

  • add a link to a submodule
git submodule init [link]
  • clone or update the submodule
git submodule update

Delete

  • remove a file from the server
git rm
  • revert a commit by adding the opposite modifs
git revert [commit]

Conference git 42

git rebase git rebase-interactive [pick: use commit] [reword: rename] [edit: stop to amend ] [squash: merge in the previous commit] [drop: ignore]

git reflog: give compelte history of git command used, usefull when one commit disappear (it has not disappear, reference of the commit has just been lost, and can be recover through reflog)