quinta-feira, 10 de outubro de 2019

Git Tutorial - Jorge D.R. Medina - Unitn/Ingegneria del Software II


Slides here, show all commands in detail

Interesting online tutorial - Learn Git Branching

Git General Commands:
·      git init – to create a new git repository on your current folder
·      touch <name of the file> – create a file
·      git add <name of the file> - add a file that is already in the folder to the git staging area. If you do not specify which branch, it will add to branch master
·      git status – show the status of your files
·      git stage <name of the file>
·      git commit <name of the file>
·      git diff <name of the file> - shows what has been changed in a particular file. It does not work for staged files.
·      git diff -- staged <name of the file> - shows what has been changed in a particular file. With the --staged parameter, it now works for staged files.
·      git add . – adds everything that changed in the directory to the repository
·      git commit -v – shows what you changed after the commit is executed.
·      Git commit -m <commit message> - add the commit message in the command line and not the editor.
·      git .ignore – creates a text file where you can write the names of files and folders to be ignored by git (you may even write *.eu to ignore files of certain extensions)
·      git rm <name of the file> – removes a file from git repository and physically from the disk.
·      ls -1
·      git rm --cache <name of the file>  - removes a file only from the index, not physically from the disk
·      git log --pretty-=oneline – to view all commits
·      git show – to view the last commit
·      git show <hash> - to view a particular commit
·      git tag -a <name of the commit> -m <message> <hash> – to associate a name and a message to a particular commit. If you do not specify a hash, it will be the last ones.
·      git tag – to view the tags I have
·      git ls-files – to view what is in the git directory



Branching Commands
A branch is just a file with a hash identifier.
The modifications (snapshots) also have a hash identifier. They are more compact “delta files”.

·      git branch – shows the branches you have
·      git branch <name of the branch> - create a new branch. Before doing this, we need at least one commit.
·      git checkout  <name of the branch>- move to a branch
·      git checkout -b <name of the branch> - creates a new branch and moved to it
·      git merge <name of the branch> - merges the branch indicated by <name of the ranch> to the merge where you currently are.
Working with remotes
·      git remote add origin <name of the new repository at GitHub>
·      git push -u origin master – push the content of a repository to your GitHub repository. Then, you should enter your GitHub name and password. In the command line, you will have some statistics about your repository. The “-u” parameter means that next time you make push, you must only use the command git push, and Git already knows that you want to push the whole repository there.
·      After doing git remote and git push (two previous topics), you must refresh the GitHub page to see the modifications.
·      git pull origin master – pulls files from the GitHub directory to your local machine.


Branching model - Gitflow
When you work on teams, the team should have some kind of convention regarding branching among other things.

Gitflow is a development model that defines a strict branching strategy centered around the idea of releases.

The Gitflow model prescribes different types of branches
  • Master: this is a Versions branch
  • Develop: branch created from the Master to contain the stable developed features.
  • Feature: created from the Develop Branch for each feature being developed (not stable). When ready, the feature branch should be merged into the develop branch.
  • Release: when all features for the release are ready, a branch is created from the Develop branch. Then, the Release branch merges into the Master branch.
  • Hotfix: created from the Master branch to fix bugs very quickly. These are critical bugs that should be fixed immediately to guarantee the application to keep operating. Minor bugs can be fixed in the Feature branch. If there is more than one critical bug and they are related, they may be fixed in the same Hotfix branch. Otherwise, you should have distinct Hotfix branches. Hopefully, that will not be common.


Advanced commands:
  • git rebase – a set of commands are executed to prepare the branches for a fast forwarding merge (see slides + simulation on Learn Git Branching
  • git stash - allows us to store half-done work without doing a commit. It is as if it saves a snapshot of what we've done so far and waits for us to come back to it. If we do git status, we see an empty list
  • git stash list - allows us to check the stashes we have
  • git stash apply stash@{0} - get back to the stash identified by "stash@{0}"
  • git rebbase -i - interactive rebasing allows us, among other things, to squash multiple commits into one.

Nenhum comentário:

Postar um comentário