+ All Categories
Home > Documents > Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control...

Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control...

Date post: 11-Jul-2020
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
31
Transcript
Page 1: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?
Page 2: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

● Distributed Version Control System (VCS);● Created by Linus Torvalds, to help with Linux development;

What is git?

Page 3: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Why should I use a VCS?

Page 4: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

RepositoriesTypes of repositories:

● Private - only you and the selected contributors will see the content● Public - everybody on the internet will be able to see the content● But, there are also other options!

How to create a repository:

● git init <folder>● Through an interface on the selected host (GitHub)

Page 5: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Work area? Staging area?

Page 6: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git AddCommand: git add <name_of_file>;

● Can be folders (f.e. git add ./folder)● Can be multiple files (git add <file_1> <file_2>)● Or you can be lazy! (git add --all OR git add .)

Page 7: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git CommitCommand: git commit;

● It will open a text editor so you can insert a commit message;● Or, you can use the “-m” flag (f.e, git commit -m “message”);● You can sum up both previous commands:

○ git add -a -m “<message_to_input>”;

Page 8: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git PushCommand: git push

● Pushes all the committed files from the staging area to the repository

Page 9: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git FetchCommand: git fetch

● Retrieves the files from the repository into the Working Area

Page 10: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git PullCommand: git pull

● Actually, it’s just git fetch +git merge● Use the “--rebase” flag to rebase the commits instead of merging

Page 11: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git RebaseCommand: git rebase;

● Tries to order the commits, placing your commits at the top so you can push them to the remote repository.

● Sometimes some flags are required (--continue, --skip or --abort) depending on the changes made by the other contributors and in what do you want to commit.

Page 12: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Other commands● Git Status (Command: git status) - shows the status of your files (added

files, files that need to be added or removed, whether you are behind in the repository or you just need to push);

● Git Reset (Command: git reset HEAD) - resets your commit into the last state of the system (you’ll typically need to add again the files);

● Git Checkout (Command: git checkout -- <path_to_file>) - undo the changes in the selected file, resetting it to the previous commit state;

● Git Rm (Command: git rm <path_to_file>) - removes the selected file from being tracked by Git;

Page 13: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Branches● Branches are a great way to to split development of a project:

○ You can create a branch to clean bugs and stabilise the codebase, and another to continue the development of a functionality.

○ However, branches can lead to headaches! Problems with merging the branches, problems with bugs on one branch, etc…

● So, we recommend that you stay with a single branch, and resort to rebasing the commits instead of merging;

● Command: git branch;○ You can list the branches existent (git branch);○ You can create a new one with (git branch <name_of_the_new_branch>);○ And you can also delete a branch (git branch -d <name_of_the_branch>);

Page 14: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

● Command: git checkout;○ Use it with branches:

■ Checkout a branch (git checkout <name_of_branch>); ■ Create a branch and switch to that one (git checkout -b <name_of_new_branch>);

● Now, to merge the branch…● Command: git merge;

○ Merge another branch with the actual branch (git merge <name_of_branch_to_merge>);

● A use case scenario:○ git checkout -d new_feature;○ git add new_file;○ git checkout master;○ git merge new_feature;

Branches

Page 15: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Blame● Command: git blame <name_of_file>;● Allows you to show who was the author of each line of a file and in what

commit it was last placed

Page 16: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Grep● Command: git grep <flags> <pattern>● This command finds all the files with string that match the given pattern● Useful flags:

○ -n Show the line number where the string matches the pattern○ -i Ignore case of the letters in the pattern○ -l List all the files with strings that match the pattern

Page 17: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Git TagsCommand: git tag <name_of_the_tag>;

● There are two kinds of Tags:○ Annotated, complete with checksum and integrity checking (f.e. git tag -a <tag>);○ Lightweight, just a simple pointer to a commit;

● You have to manually push the Tags (git push --tags);

Page 18: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Now, let’s talk about Github!

Page 19: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

We’ve got a great help...● Unlimited private repositories;● Money to use on cloud services like Amazon Web Servers, Digital Ocean,

Bitnami● Software like Unreal Engine, Atom, Travis CI

Page 20: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

A little about project management...Github gives you two powerful tools that helps you manage your project:● Wiki - lets you document your code and provide additional information to

anyone that needs;● Issue Tracker - lets you manage which responsibilities are in a project, assign

them to a developer, maintain an idea of what needs to be done;

Page 21: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Github’s motto: Social Coding!● Github lets you host free public repositories;

○ They want you to share your code and get help from the community!

● Open source your projects! ○ But how do I manage which commits are beneficial?○ Pull Requests!

● Organizations!

Page 22: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Share snippets of code: Gist● Gist is the snippet tool of Github;

○ Easy to use; ○ Share it with whom you want;○ Formats like code;○ Can be public, or you can make it private;

Page 23: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Github Pages● Serve a page about your project using Github!

○ Github pages allow you to setup a blog using Jekyll;○ You can setup a custom URL!

● So, how do you create one?○ Create a public repository with the name (<your_username>.github.io);○ Done!

Page 24: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Markdown● What is Markdown?

○ Text-to-html conversion tool;

● Github supports Markdown in its pages (using Github-flavoured Markdown);

○ Commit messages;○ Wikis;○ Issues;

Page 25: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

You can also use SSH! You can create Webhooks!● You can also setup SSH in order to push the commits!

○ Don’t need to insert to credentials for every push;○ Allows automation of pushes and pulls (we always use Fabric, a Python module, to push

our commits onto our repositories);

● Webhooks let you modify something when there is an event:○ For example, send a new commit onto Travis CI (a continuous integration service);

Page 26: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Using github for your projects● Ask for the student pack (https://education.github.com/pack)● Create private repositories, you can setup one repository per project● Add your collaborators (if you have any) and you’re ready to go

Page 27: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Good practices of working with git● Make short but meaningful commits (a new function, for example);● Associate a descriptive message so you can know what was changed;● Don’t push code that doesn’t work, except in some special situations;● Distribute the work with issues or other collaboration tools (e.g. Trello);● Don’t hold your commits too long so your colleagues may know what is

happening;● Look at your colleague’s commits, you may find there some bugs to fix or

the solution to a problem that you don’t know how to solve;

Page 28: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Finally, to wrap up...● There are multiple GUI Clients:

○ SourceTree (Windows);○ GitCola (Linux);○ Github Desktop (Windows, Mac);○ GitKraken;

● Other kinds of VCS:○ SVN;○ Subversion;○ CVS;

● Other Hosts:○ Gitlab;○ Bitbucket;

Page 29: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Questions?

Page 30: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Now let’s test everything we learned...● Create a github account (if you haven’t one yet);● Pair with a colleague, one person of the pair should create a public

repository● Both of you should clone the created repository;● One person should create a file and push it to the repository (remember

the steps: git add, git commit, git push);● The other person should pull the file from the repository, change it and

push again;● Finally, let’s simulate some conflicting changes. Both of you should change

the file and commit it. When the second person tries to push the file, both of you will have to work together to solve the conflict.

Page 31: Distributed Version Control System (VCS);neiist.daemon/docs/GitHub.pdfDistributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development; What is git?

Thanks for coming!


Recommended