[git] - Git Basic Formation
Why? What? How? Git is a collection of command line utilities that track and record changes in files. With it you can restore old versions of your project,...
Git is a collection of command line utilities that track and record changes in files.
With it you can restore old versions of your project, compare, analyze, merge changes and more. This process is referred to as version control.
Git is decentralized, which means that it doesn’t depend on a central server to keep old versions of your files. Instead it works fully locally by storing this data as a folder on your hard drive, which we call a repository.
A commit is a textual representation of change append to files.
A commit is defined by few data
This textual representation is done by only few directives
This textual representation is more or less what you get using git diff
.
Git use an internal graph to store repository history. Each commit is a node of this graph and MUST have only one parent.
The index can be simply explain as a “future commit”.
It contain the textual representation of change added to the index (using git add path/to/file.ext
).
Using git status
, show content of the index with all files flagged as tracked.
Alias: git st
Installing Git on your machine is straightforward:
sudo apt-get install git
If you are an absolute beginner, then a graphical git client is a must. Since you are an absolute killer at programming you need to use and understand every command of git.
There are a lot of options that can be fiddled with, but we are going to set up the most important ones: our username and email. Open a terminal and run these commands:
git config --global user.name "My Name"
git config --global user.email myEmail@example.com
You can also custom git configuration editing ~/.gitconfig
file.
Here is an example of advanced configuration.
There are a set of rules to keep in mind:
Perform work in a feature branch.
Because this way all work is done in isolation on a dedicated branch rather than the main branch. It allows you to submit multiple pull requests without confusion. You can iterate without polluting the master branch with potentially unstable, unfinished code. read more…
Branch out from develop
This way, you can make sure that code in master will almost always build without problems, and can be mostly used directly for releases (this might be overkill for some projects).
Never push into develop
or master
branch. Make a Pull Request.
It notifies team members that they have completed a feature. It also enables easy peer-review of the code and dedicates forum for discussing the proposed feature.
Update your local develop
branch and do an interactive rebase before
pushing your feature and making a Pull Request.
Rebasing will merge in the requested branch (
master
ordevelop
) and apply the commits that you have made locally to the top of the history without creating a merge commit (assuming there were no conflicts). Resulting in a nice and clean history. read more …
Delete local and remote feature branches after merging.
It will clutter up your list of branches with dead branches. It ensures you only ever merge the branch back into (
master
ordevelop
) once. Feature branches should only exist while the work is still in progress.
Before making a Pull Request, make sure your feature branch builds successfully and passes all tests (including code style checks).
You are about to add your code to a stable branch. If your feature-branch tests fail, there is a high chance that your destination branch build will fail too. Additionally, you need to apply code style check before making a Pull Request. It aids readability and reduces the chance of formatting fixes being mingled in with actual changes.
Protect your develop
and master
branch.
It protects your production-ready branches from receiving unexpected and irreversible changes. read more… Github, Bitbucket and GitLab
Why? What? How? Git is a collection of command line utilities that track and record changes in files. With it you can restore old versions of your project,...
Be a good developer, follow the guideline.
My team follow this for day to day usage.
Keep in mind this just an overview of how each command interact with git.
Git is a collection of command line utilities that track and record changes in files.