What is a “version control system”?Version control systems are software tools that help record changes made to files by tracking modifications in the code.
Why Version Control system is so Important?
A version control system, also known as VCS, plays a crucial role in software development by providing a structured approach to managing code changes. It enables development teams to effectively collaborate, track, and document modifications made to the source code. With a VCS in place, developers can easily identify who made specific changes, what those changes entail, and when they were implemented, fostering better communication and organization within the team.
It’s like having an “undo” button for your work, just like the one in your operating system. It keeps track of all the changes happening in your system. So, if you accidentally make a change you didn’t mean to, you can easily go back to the most recent version you saved on your computer.
Let’s simplify this with an example: Imagine a developer is asked to make changes to a set of code without disrupting the existing code. If the changes don’t meet the client’s expectations, the developer would have to manually review and undo all the modifications. This process can be time-consuming, especially if the codebase is large. To avoid this hassle, we use VCS like Git. Git helps store the source code in software development and track its changes. It allows developers to work together on repositories, managing different versions of the codebase and keeping a history of project changes.
What is the difference between git and gitHub?
GitHub is a hosting service or database tool which hosts Git repositories online. It helps users share their git repository online, with other users, or access it remotely. You can also host a public repository for free on GitHub.
User share their repository online for various reasons including but not limited to project deployment, project sharing, open source contribution, helping out the community and many such.
GitHub is like a friendly online space where you can store your Git repositories. It allows you to share your code with others, work on it remotely, and even host public repositories for free. People use GitHub to deploy projects, share their work, contribute to open-source projects, help the community, and more. It’s a cool way to collaborate and showcase your coding skills!
Git is a software tool utilized in software development to store source code and track changes. It enables developers to collaborate on repositories, managing different versions of the codebase and maintaining a history of project modifications. By using Git, developers can easily navigate through various project states, merge changes effectively, and ensure a structured and efficient approach to software development.
INSTALLATION & GRAPHICAL USER INTERFACES
GitHub offers platform-specific installers for Git, ensuring users can easily keep up-to-date with the latest releases of the command line tool. Additionally, GitHub provides a graphical user interface for daily interactions, reviews, and repository synchronization.
- GitHub desktop: https://desktop.github.com/
- Sublime merge: https://www.sublimemerge.com/
SETUP
Configuring user information used across all local repositories.
git config –global [user.name](http://user.name) “[firstname lastname]”
Set a name that is identifiable for credit when reviewing version history.
git config –global [user.email](http://user.email) “[valid-email]”
Set an email address that will be associated with each history marker.
SETUP & INIT
Configuring user information, initializing, and cloning repositories.
- git init -> Initialize an existing directory as a Git repository.
- git clone [URL] -> Retrieve an entire repository from a hosted location via URL.
STAGE & SNAPSHOT
Working with snapshots and the Git staging area.- git status -> shows modified files in the working directory, staged for your next commit.
- git add [file] -> Add a file as it looks now to your next commit (stage).
- git reset [file] -> unstages a file while keeping the changes in the working directory.
- git diff -> shows the difference in what is changed but not staged.
- git diff –staged -> shows the difference in what is staged but not yet committed.
- git commit -m “[descriptive message]” -> commits your staged content as a new commit snapshot. (The message should not exceed a character limit of 50)
BRANCH & MERGE
Isolating work in branches, changing context, and integrating changes.
- git branch -> List your branches, an asterisk will appear next to the currently active branch.
- git branch [branch-name] -> Create a new branch at the current commit.
- git checkout -> Switch to another branch and check it out in your working directory.
- git merge [branch] -> merge the specified branch’s history into the current one.
- git log -> Show all commits in the current branch’s history.
INSPECT & COMPARE*
Examining logs, differences, and object information.
- git log -> displays the commit history for the currently active branch.
- git log branchB..branchA -> shows the commits on branch A that are not on branch B.
- git log –follow [file] -> displays the commits that changed the file, even after renaming.
- git diff branchB…branchA -> shows the difference between what is in branch A and what is not in branch B.
- git show [SHA] -> displays any object in Git in a readable format.
TRACKING PATH CHANGES
Versioning files involves removing and tracking path changes. - git rm [file] -> deletes the file from the project and stages the removal for commit.
- git mv [existing-path] [new-path] -> changes the path of an existing file and stages the move.
- git log –stat -M -> displays all commit logs with an indication of any moved paths.
IGNORING PATTERNS
Preventing accidental staging or committing of files.
logs/
*.notes
pattern*/
To prevent files from being staged or committed unintentionally, save a file with the desired patterns as .gitignore. You can use direct string matches or wildcard globs.
git config –global core.excludesfile [file]
This sets a system-wide ignore pattern for all local repositories.
SHARE & UPDATE
Retrieving updates from another repository and updating the local repository.
- git remote add origin [URL]: Maps the local folder with the remote GitHub repo.
- git fetch [alias]: Fetches all the branches from that Git remote.
- git merge [branch]: Merges a remote branch into your current branch to update it.
- git push origin [branch]: Sends local branch commits to the remote repository branch.
- git pull: Fetches and merges any commits from the tracking remote branch.
REWRITE HISTORY
Rewriting branches, updating commits, and clearing history.
- git rebase [branch]: Applies any commits of the current branch ahead of the specified one.
- git reset –hard [commit]: Clears the staging area and rewrites the working tree from the specified commit.
TEMPORARY COMMITS
Store modified, and tracked files temporarily to switch branches.- git stash: Saves modified and staged changes.
- git stash list: Lists the stack order of stashed file changes.
- git stash pop: Restores working from the top of the stash stack.
- git stash drop: Discards the changes from the top of the stash stack.
Share your newfound knowledge with others and encourage them to explore the world of version control systems with Git and GitHub! Happy coding and collaborating!
Source: hashnode.com