Skip to content

Instantly share code, notes, and snippets.

@tdutrion
Last active February 17, 2017 15:30
Show Gist options
  • Save tdutrion/eee287e5eb5c0ae51ce146b0008a6151 to your computer and use it in GitHub Desktop.
Save tdutrion/eee287e5eb5c0ae51ce146b0008a6151 to your computer and use it in GitHub Desktop.
Git - Nicolas

Reminders versionning ecosystem

Approval %

  • svn
  • bazaar
  • git
  • mercurial
  • ...

Git

distributed system

Works locally, allow to push on anyone's repository

Allow offline work but requires the developer to

A commit is represented with a sha1 hash.

stages

Working directory

Where we create files, but they are not linked to the repository in any way.

staging area

We add files to an index, so now they are tracked.

commit

Example

git init
git add file.txt
git commit -m "Initial commit"

Introduction of HEAD: HEAD is a link to a sha1 hash (commit).

git add file2.txt file3.txt
git commit -m "Added file2 file3"

HEAD moved to the new commit number.

echo "test" >> file2.txt
git commit -a -m "message"

Branching:

git branch myidea

The branch is created but the HEAD is still on the master branch.

git checkout myidea

Move the HEAD to the myidea branch.

echo "test" >> file3.txt
git commit -a -m "message"

Moving back to master

git checkout master

The HEAD is back on the top of master, so does not contains the edit of the file3.txt done on the myidea branch.

git merge myidea

This creates a new commit on the current branch (master) that contains the commits from the myidea branch.

Explanation of merging master on a feature branch.

git checkout myidea

The HEAD is back on the commit 4.

Once the feature is finished, we can delete the feature branch:

git branch -d myidea

Remote branches

Clone a repository. You get a master branch as the repository, but also an origin/master.

When a dev adds 2 commits, and we do add 2 commits too.

origin (the default naming convention for the remote branch)

git fetch origin

Fetches the state of the remote (so the branch origin/master gets the 2 new commit from the other developers.

git status will inform you of the differences

git merge origin master

git push origin master

Introduction to workflows

No one on master (deployable branch, can be deployed at anytime)

A development branch usually receive the developers commit. Developers work on feature branches and then merge back to development.

Rewriting the history

Warning: be careful, do it only on your own branch.

--amend rebase

Debug with bisect

Interactively move the HEAD back and forth, asking for each move whether you still have the bug.

Excercice

Interactive tutorial from Github and Codeschool

Best practices

  • Commit message should be meaningful
  • Having lots of small commits is better than on massive one, as it allows to revert a single commit, whereas you probably would not revert a massive commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment