weekly-coordination
December 19, 2022

Git & GitHub

Are you ready to jump into the world of VCS?

That's awesome. Let's do that together!

Basic background

What is VCS and how it functions? 🤔

Version control is a system that records changes to a file or set of files over time so that we can recall specific versions later.

3 types of VCS's

⬇️ ⬇️ ⬇️ ⬇️

Local VCS
  • Only for applying modifications inside your own computer.
  • If anybody needs some version, that person should come and take the version by copying that into their flash drive.
  • If something is accidentally deleted, you cannot get that afterwards if others had not copied that beforehand.
Centralized VCS
  • There is a separate machine that saves the versions of your files.
  • If something is deleted from your computer, just recover that from the above machine.
  • But, what if the machine will stop working as well???
Distributed VCS
  • Each computer has a VCS on it.
  • Now, we can recover information confidently.

Dive into Git & GitHub

What power do we have now? 💪😎👍

Distributed VCS is the real power. We can see that by just looking at Git.

Git Features


  • Distribution
  • Size and Speed
  • Data Assurance
  • Open Source
  • Branching and Merging
  • Detailed information about them - https://git-scm.com/about

Git installation


Git download page - https://git-scm.com/downloads

Configuration


Template: git config --global <key> <value>
-> git config --global user.name "Your Name"
-> git config --global user.email [email protected]

File States


The ”git commit” command captures a snapshot of the project's currently staged changes. “git add” tells that you want to include updates to a particular file in the next commit

Commits & Branches


A branch in Git is simply a lightweight movable pointer to one of commits. Branching means, you diverge from the main line of development and continue to do work without messing with that main line
*HEAD is one of the pointers. For every branch, there's a *HEAD pointing to the last commit.

Commit


-> git add <filename>
-> git commit -m "a clear message"

Git add


Add changes in working directory to the staging area:
-> git add <filename> [<filename>]
A command that accepts wildcards as parameters:
-> git add *.py
A dot ‘.’shortcut is used to add all files:
-> git add .
For tracking current changes, use:
-> git status
It is not recommended to do the git add . and git add -A for not adding unnecessary files.

.gitignore


A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected. Each line in a gitignore file specifies a pattern. Detailed explanation: https://git-scm.com/docs/gitignore

Git commit


“git commit” is used to commit the staged files to the repo. 
The default file editor will be opened to allow you to add commit message:
-> git commit
Use -m parameter to add inline commit message instead:
-> git commit -m “first commit”
Add staged changes to the last commit:
-> commit --amend
In the process of using commit --amend, we can also change the message of the commit. To avoid that, we can use a flag --no-edit

Branches


View the list of existing branches:
-> git branch
Create a new branch:
-> git branch feature
Switch to the branch:
-> git checkout feature
Short alias to create new branch and switch to it:
-> git checkout -b feature
When we create a branch, it is created from the last commit that is in the current branch

Merging


Just imagine you have the repository represented, and you need to have your feature
in the master branch.
We can use git merge command.
Git creates a new snapshot and automatically creates a new commit that points to it. This is called as a merge commit and it has more than one parent
-> git merge feature
If there's a conflict on merging branches, Git will open a git merge and show on which files you have conflicts. And, you have to deal what way to choose.

Rebasing


It is the process of moving the base of our branch from one commit to another making it appear as if we had created our branch from a different commit.
-> git rebase master
It is a powerful feature. But, there could be some issues related to commits, so make sure that only you are working on one branch.

How to get a repository?


Create a new repo:
-> git init
Get an existing repo:
-> git clone https://github.com/username/repo
Default name for remote repo is origin

Push & Pull (changes from the server)


To update remote refs using local refs and simply push changes to 
remote repo: 
-> git push
To take changes from remote repo and try to merge them to our local one:
-> git pull 
It also works like a combination of merge and fetch commands for our local 
changes.

Commit History & File Changes


To show full commit history:
-> git log
To list all comments which were made from <commit 1> to <commit 2>
(<commit 1> is not included):
-> git log <commit 1>..<commit 2>
To show differences between files in two commits or between our 
current repo and a previous commit:
-> git diff

Hu-uh! 😶‍🌫️

That's a lot of information.

It is not easy to grasp that much details at first, but that doesn't mean it's impossible. It happens with almost everybody. Those who have found a special key can learn everything, and that key is consistency, my friend 😎

Thank you for your time with us. Keep learning and winning 🚀

Need more?

Video materials 📺

Credits 👏

  • EPAM Training Center - All of the materials have been taken from the EPAM Python Training 2022.03. I express my gratitude to them for providing such great details on trending topics. Hope, you enjoy this as well!