GIT
Git is a version control system (VCS) that allows you to track changes to files and collaborate with others on software development projects. It was created by Linus Torvalds, the creator of the Linux operating system, and is widely used in the software development industry.
What is Version Control BDY??
Version control system means that Git is a tool/system that keeps track of various versions of your project you have done previously.
Distributed version control system means that with Git every collaborator (developer) working on a team project has a local copy (repository)of the project on his or her personal computer.
Why do we use Git?
Git has over time become an industry standard for development. With Git you can;
Using GIt..you can step back or forward with your initial project version and redo/undo the project mistakes.
You will be able to see the whole project changes and modifications
Whenever you are doing a big project that has many features, you can use Git to work on different features separately without causing conflict with other features in the project.
Sharing projects codes Pulling, Pushing, Teamwork.
Thress Git Stages:
Modified - means that you have changed the file but have not committed it to your database yet.
Staged - means that you have registered a file in its current version to go into your next git snapshot.
Committed - means that the data and modifications (changes) you made to the file are safely stored in your local database.
Jump Start to Git Command Codes========================
Configuration Method
(Configuration in Git allows you to customize and personalize your Git environment)
Configure user information for all local repositories
$ git config --global
user.name
"[name]"
Sets the name you want attached to your commit transactions
$ git config --global
user.email
"[email address]"
Sets the email you want attached to your commit transactions
$ git config --global color.ui auto
Enables helpful colorization of the command line output
Branches
(enables multiple individuals or teams to work on different features, bug fixes, or experiments simultaneously without interfering with each other's work.)
Any commits you make will be made on the branch you’re currently “checked out” to. Use git status
to see which branch that is.
$ git branch [branch-name]
Creates a new branch
$ git switch -c [branch-name]
Switches to the specified branch and updates the working directory
$ git merge [branch]
Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.
$ git branch -d [branch-name]
Deletes the specified branch
Create repositories
(works as central hub for version control, history tracking, and code sharing, sharing each teams to work together)
A new repository can either be created locally, or an existing repository can be cloned. When a repository was initialized locally, you have to push it to GitHub afterwards.
$ git init
The git init command turns an existing directory into a new Git repository inside the folder you are running this command. After using the git init
command, link the local repository to an empty GitHub repository using the following command:
$ git remote add origin [url]
Specifies the remote repository for your local repository. The url points to a repository on GitHub.
$ git clone [url]
Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits
The .gitignore file
Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore
. You can find helpful templates for .gitignore
files at github.com/github/gitignore.
Synchronize changes
Synchronize your local repository with the remote repository on GitHub.com
$ git fetch
Downloads all history from the remote tracking branches
$ git merge
Combines remote tracking branches into current local branch
$ git push
Uploads all local branch commits to GitHub
$ git pull
Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull
is a combination of git fetch
and git merge
Make changes
Browse and inspect the evolution of project files
$ git log
Lists version history for the current branch
$ git log --follow [file]
Lists version history for a file, beyond renames (works only for a single file)
$ git diff [first-branch]...[second-branch]
Shows content differences between two branches
$ git show [commit]
Outputs metadata and content changes of the specified commit
$ git add [file]
Snapshots the file in preparation for versioning
$ git commit -m "[descriptive message]"
Records file snapshots permanently in version history
Redo commits
Erase mistakes and craft replacement history
$ git reset [commit]
Undoes all commits after [commit]
, preserving changes locally
$ git reset --hard [commit]
Discards all history and changes back to the specified commit
CAUTION! Changing history can have nasty side effects. If you need to change commits that exist on GitHub (the remote), proceed with caution. If you need help, reach out at github.community or contact support.
Glossary
git: an open source, distributed version-control system
GitHub: a platform for hosting and collaborating on Git repositories
commit: a Git object, a snapshot of your entire repository compressed into a SHA
branch: a lightweight movable pointer to a commit
clone: a local version of a repository, including all commits and branches
remote: a common repository on GitHub that all team members use to exchange their changes
fork: a copy of a repository on GitHub owned by a different user
pull request: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more
HEAD: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using
git switch