Many way to define Control system (VCS) or software configuration management (SCM) system.
- Program or set of programs that tracks changes to a collection of files.
- Allow many to work on a project in a coherent way.
- Create by Linus Torvalds, the creator of Linux because he did need it.
- See all the changes made to your project, when the changes were made, and who made them.
- Include a message with each change to explain the reasoning behind it.
- Retrieve past versions of the entire project or of individual files.
- Create branches, where changes can be made experimentally. This feature allows several different sets of changes (for example, features or bug fixes) to be worked on at the same time, possibly by different people, without affecting the main branch. Later, you can merge the changes you want to keep back into the main branch.
- Attach a tag to a version—for example, to mark a new release.
Work files without a network connection, check them in locally, and sync with the server when a connection becomes available.
You must be very clear with terminology:
- Working tree
Set of nested directories and files that contain the project that's being worked on.
- Repository (repo)
Directory, located at the top level of a working tree
Git keeps here all the history and metadata for a project.
- Bare repository
Respositorythat isn not part of a working tree; it's used for sharing or backup, usually a directory with a name that ends in .git
Number produced by a hash function that represents the contents of a file or another object as a fixed number of digits. Hashes usd by Git to tell whether a file has changed by hashing its contents and comparing the result to the previous hash.
- it's a repo ant contains four types of objects, each uniquely identified by an SHA-1 hash.
- Blobobject contains an ordinary file.
- Treeobject represents a directory; it contains names, hashes, and permissions.
- Commitobject represents a specific version of the working tree.
- Tag - name attached to a commit.
Committing (doing) the changes you have made so that others can eventually see them, too.
Series of linked commits with agiven name.
The most recent commit on a branch is called the head.
The default branch, which is created when you initialize a repository, is called main
The head of the current branch is named HEAD.
A named reference to another Git repository. When you create a repo, Git creates a remote named origin that is the default remote for push and pull operations.
- Commands, subcommands, and options
Git operations are performed by using commands like git push and git pull. git is the command, and push or pull is the subcommand.
Commands frequently are accompanied by options, which use hyphens (-) or double hyphens (--). ie. git reset --hard.
- Cloud platform that uses Git as its core technology.
- Simplifies the process of collaborating on projects and provides a website, more command-line tools, and overall flow that developers and users can use to work together.
- Act s as the remote repository mentioned earlier.
- Key features:
- Pull requests
- git config
set who operate: name & email
- git init,git checkout
Init git and set active branch
- git add
keeep track of files
- git commit
commit changes (need a name)
- git log
see data about commits
- git help
Projects are iterative. Write some code, test, patch, others work o n the same project, multiple branches are merged, errors and ... voala problems.Using git you can keep all this mess under control.
- git log
- git diff
- .gitignore (file)
Prevents extraneous files from being submitted to version control. Boilerplate .gitignore files are available for popular programming environments and languages.
Git doesn't consider adding an empty directory to be a change.
To have empty directories as placeholders. A common convention is to create an empty file, often called .git-keep, in a placeholder directory.
Put small changes in the same commit as the original.
git commit --amend --no-edit
Recover a deleted file
git checkout -- <file_name>
if file was deleted with git rm:
git reset -- <file_name>
Revert a commit
Collaborate on project
- git clone
Clone a repository
When Git clones a repository, itcreates a reference to the original repo that's called a remote by using the name origin.
- git pull
Copies changes from the remote repository to the local one - only new commits.It already knows the last commit that it got from the remote repository because it saved the list of commits.
Git pulls or pushes only when you tellit to do so.
- git pull-request - p origin/main .
Other users can create a pull request, ask you, as main developer to pull their work and commit into main branch.
A pull request gives you a chance to review other collaborators' changes before you incorporate their work into the work you're doing on the project.
- git remote
The project owner, you need to know how to merge pull requests:
git remote - to set up another developer's repo as a remote
git pull - use that remote for pulls and pull requests
git pull is a combination of two simpler operations: git fetch, which gets the changes, and git merge
You MUST set up a central repository, which is also called a bare repository -repository that doesn't have a working tree.
- Everybody can push changes without worrying about which branch is checked out (no working tree)
- Git can detect when another user has pushed changes that might conflict with yours.
- Shared repo can scales to any number of developers.
- Shared repo on a server that you all can access - no worry about firewalls and permissions.
- No need separate accounts on the server because Git keeps track of who made each commit.
Hands-On Get started with Git, Login to view
Hands-On Start a project with Git, Login to view
Hands-On Collaborate with Git , Login to view