Git & Github Tutorial: Jorge Ramírez
Git & Github Tutorial: Jorge Ramírez
Jorge Ramírez
Slides: https://tinyurl.com/se2-git-tutorial [email protected]
Part #1
Git basics
Getting a Git Repository
$ git init
$ git clone
Configuring git
$ git config
$ git add
$ git commit
Checking status and changes
$ git status
$ git diff
Ignoring files
$ cat .gitignore
*.pyc
Removing files
$ git rm
Viewing commits
$ git log
$ git show
Tags
Tags can be
lightweight or
annotated
$ git tag
annotated
$ git tag -a v0.1.0 -m "version 0.1.0"
lightweight $ git tag v0.1.0 tag a specific
$ git tag -a v0.1.0 6bc0f6b commit
Branching
How git works: snapshots
Pointer to
File B
How git works: commit
$ git add README test.rb LICENSE
$ git commit -m "Initial commit"
blobs
commit snapshot
Git's default
branch name
● autolinked references
https://help.github.com/en/articles/autolinked-references-and-urls
● closing issues
https://help.github.com/en/articles/closing-issues-using-keywords
Branching model
Gitflow
Gitflow is a development model that defines a strict branching strategy centered
around the idea of releases.
Elements
References
https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
https://nvie.com/posts/a-successful-git-branching-model/
Master and Develop branches
Pointer to
the current
branch
Our directory
$ git init
$ git add
$ git commit
Git takes what's on the Index and creates an snapshot, a commit object and updates master.
Source: The git book
Understanding git reset: git status revisited
Changes not staged for commit (diff between Index and Working directory)
Steps
1. Move HEAD
2. Update Index
3. Update Working Directory
Like doing git reset --hard develop Like reset, it does not move HEAD. And it is
in that git updates the "three trees" to look like similar to git reset [branch] file
the develop branch. Then checkout updates BUT it also updates the Working Directory.
HEAD to point to the develop branch.
Editing our last commit
$ vi $HOME/.gitconfig
How can I "see" what's on the Index? (1/2)
The Index is our proposed changes for the next commit, also known as the
"staging area". So this question is twofold:
● git status shows what's going to be part of the next commit. But it shows
only the files we changed and staged using git add. However, in the Index,
there are also files that didn't change. And for this unchanged files, Git stores
a pointer to the last snapshot of the file.
● But once we committed, we can inspect the Index by:
○ Using git show and see what was part of our last commit.
■ git show --stat
○ Using git ls-file and inspect how the Index currently looks like. This is a
plumbing command. A concrete example of this on the next slide.
■ git ls-files --stage
How can I "see" what's on the Index? (2/2)
We see the index of our
last commit. Here, git
status will show you
"nothing to commit".