πWhat is a Git?
Git is an open-source distributed version control system(DVCS). Especially, it is a system used to record changes to files over time, so you can see what all changes you have made later on.
A version control system simply tracks the history of changes whenever people or team collaborate to do project together. As the project evolves team can test, run and contribute to the code with confidence that any version can be recovered anytime if something happens. Developers can review the following:
- Which changes were made?
- Who made the changes?
- When were the changes made?
πWhat is a GitHub?
GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code. GitHub's interface is user-friendly enough so that the novice coders can take advantage of Git. Without GitHub, using Git generally requires a bit more technical savvy and use of the command line. With addition to that, anyone can SignIn and host a public repository freely which makes GitHub especially popular with open-source projects.
πHow to install Git?
You can download your Git version according to your OS. Here is the Link
πGit Commands
git init
Syntax : git init <directory>
-
git clone
Syntax : git clone <repo>
git add
Syntax : git add <directory>
git commit -m
Syntax : git commit -m <message>
git status
Syntax : git status
git branch
Syntax : git branch
git merge
Syntax : git merge <branch>
git pull
It updates the local line of development with updates from its remote counterpart. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.
Syntax : git pull --rebase <remote>
git push
It updates the remote repository with any commits made locally to a branch.
Syntax : git push <remote-repo> --all
πMove backward to the previous state
If we found a bug, we must trace from the beginning of the code, looking into line per line of codes. Git simplifies our work with the move backward feature. Instead of looking from the beginning of works, we can track based on the previous commit before a bug was found. There are three commands to move back on git. It is used for our needs.
git checkout
: it is like a time machine, we can restore the condition of the project file to the designated time. However, this is temporary. These are not stored in the git database
git reset
: this command makes us unable to go back to the future. We will lose our commits. After the git logs were reset, we need to write a new commit
git revert
: will take the existing file condition in the past, then merge them with the last commit
πGit Lifecycle
The git lifecycle is divided into four states namely:
Modified : any changes didnt been marked yet. We can do anything here, manipulate files, create or delete a new folder, and other things.
Staged : a condition when our changes have been marked but didnt been recorded yet.
Committed : folders or files successfully are been recorded into our .git folder.
πStart a new repository and publish it to GitHub
Let's create a new repository and publish it to GitHub. Do not initialise the repository with a README, .gitignore or License. This empty repository will await your code.
# create a new directory, and initialize it with git-specific functions
git init my-repo
# change into the `my-repo` directory
cd my-repo
# create the first file in the project
touch README.md
# git isn't aware of the file, stage it
git add README.md
# take a snapshot of the staging area
git commit -m "add README to initial commit"
# provide the path for the repository you created on github
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
# push changes to github
git push --set-upstream origin master
git push -u origin master (Alternative)
πSummary
This is the end of our tutorial, coders! Learn more about the git cheat sheet!
Thanks for reading this blog. Hope you have liked it!π
Top comments (0)