Basics of working with Git
Git is an open-source version control system that can be used efficiently to manage projects. Version control maintains a track of projects over time and keeps a complete history of the changes on a project similar to a file manager. It also allows developers to collaborate on the same project. GitHub is a site that hosts Git repositories.
GitHub Terminologies
Fork: Fork is a replication of another user's repo that lives on one's personal Github account.
Main: A default development branch when a new repository is created.
Readme: A basic plain text file that contains information about other files in a repository that serves as documentation.
Repository: A Repository is where work is stored in a directory or storage space. A shorter form is known as "repo."
License: It allows the repo to be genuinely open-source. Once licensed, others can use, modify, and distribute it.
Pull request: This allows one to announce a change made by someone in the branch. Pull requests are ways for developers to let the team know when they've finished working on a feature.
Git Commands
git init: The git init command initializes (creates) a new Git repository. A .git subdirectory is created in the current working directory containing all metadata.
git clone: git clone creates a copy of a specific repository or branch within a repository.
git branch <branch-name>: This git command creates a new branch for a specific repository.
git checkout <branch-name>: This command lets you navigate between the branches created by the git branch.
git add: The git add command directs Git to "save" a snapshot of the current project state into the commit history. It tracks the file and its changes in Git.
git commit: The git commit command takes a snapshot of the current state of the project's changes.
git push: The git push is used to upload git commits to a remote repository like Github
There are three states in git
Modified — When some file is modified in the repo.
Staged — When modifications are done, and files are staged.
Committed — When staged files are finalized and committed
Basic git Setup //create a new folder mkdir testing //Navigate to the new folder cd testing //Create a new file within the testing directory touch test.py //Check untracked changes in the test.py file. git status //To add test.py file git add test.py //To commit your changes git commit -m "<add a comment for your commit >" //Add your remote origin link, use it to link a repo within GitHub, or create a new repo git remote add origin main https://github.com/shasheen/<directory> //Push your code to GitHub git push -u origin
Whenever you get a chance, do play around with Git. It avoids the possibilities of overwriting content on a file, thinks about data, stores snapshots, and maintains the integrity of files. It is a crucial part of a development lifecycle and essential for collaboration.