DEV Community

Cover image for Git & Github
Abhishek Avati
Abhishek Avati

Posted on

Git & Github

  • Imagine you have a project or application and you want to collaborate with other people.
  • Saving your development process in different checkpoints and you wish to go back to particular checkpoint.
  • So git and github help us to contribute on a project with other people, we can save history of every new feature added to project

What is Git ? Git is a free and open source distributed version control system designed to handle everything from samll to very large projects with speed and efficiency

What is Github ? : Github is an online platform which allow us to host our project repository.

Why we use Git and Github ?

  • sharing our code with the world
  • maintaining history of the project.
  • who made the changes, when the changes occurred.

How we use Git
download GIT from here,

we will use git from command line interface.

all the history of our code/project is being stored under the folder called as .git

how to initialise the git repository in our project.
enter command $git init which will initialise the git repository in current project.
It will be hidden, so it wont be visible to us.

$git status : This commands tells which files are not tracked to git repository commit or what is the current status of overall repository.

I have created a file which is not staged or commited to repository
so the status will be as followed

pic 1

$git add . This command will transfer all the un-tracked files to the staging area and '.' represent all files should be added to staging area.
If we want to add a specific file to staging area then we write it as
$git add filename

pic 2

$git commit -m "your message here" The git commit command captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to.

pic 3

$git log : this command gives the history or information of all the commits which were made previously.

$git stash : This command locally stores all the most recent changes in a workspace and resets the state of the workspace to the prior commit state

pic 4

$git stash pop : The popping option removes the changes from stash and applies them to your working file.

pic 5

$git stash clear : clear all stashes from repo

$git remote add origin url_of_remote_repository : This command add a url of a remote repository to your local repo

$git push origin main : whenever we want to update the local changes to remote repo we have to use git push command

git branch it is basically a pointer to snapshot of changes/ features we are adding that we have to get them merged with the main branch

Note : whenever you are working on a new feature always make sure that you create a branch and then work on that feature.

$git branch branchName : command to create the branch

$git checkout branchName : switch to the branch

git push origin branchName : push the changes over the branch

what is fork ? Creation of exact copy of a git repo
whenever we create a fork of repo there are two url one for original repo and other for forked repo so the original repo url is called as upstream url, this upstream url is helpful to fetch changes from the original repo into the copied repo
command for it is as follows.
$git fetch upstream / $git pull upstream main

pull request : A pull request is an event in Git where a contributor asks a maintainer of a Git repository to review code they want to merge into a project.
It opens a platform where a contributor discuss their ideas and maintainer verifies the code and rejects the pull request if there are some bugs in it.

steps to contribute any open source project

  1. fork the project.
  2. clone your forked project.
  3. check the origin of forked project.
  4. add upstream of the forked project.
  5. pull the upstream project changes.
  6. create a branch.
  7. make changes to local repo.
  8. commit those changes.
  9. push your changes to fork.
  10. make a pull request to actual project.

THE END!!
Thanks for reading!!
Hope you liked it, feel free to comment over the blog or any changes are welcomed!!
Abhishek Avati.

Top comments (2)

Collapse
 
_bkeren profile image
''

you say
$git stash pop : clear all stashes from repo
is it git stash clear:

Collapse
 
abhiavati20 profile image
Abhishek Avati • Edited

Actually git stash pop removes top instance of saved changes
While gist stash clear : clears the all the instances.
Sorry It was my typing mistake