Git and Github - A practical guide for Open Source Contribution

Git and Github - A practical guide for Open Source Contribution

A Comprehensive Guide for Beginners

Git is a Version Control Software

GitHub is a website for hosting our Git repositories remotely

Download Git from here

To Setup your Git for the first time -

$ git config --global user.name "your_name"

$ git config --global user.email your_email

Git Commands -

  1. ls - Lists the folders inside

  2. mkdir foldername - Makes a folder

  3. cd folder - Takes the control inside the folder

  4. git init - Initializes a hidden repository inside the folder

  5. ls -a - shows the hidden files

  6. ls .git - shows all the .git file

  7. touch filename - Creates a new file

  8. git status - Shows the history of the changes

  9. git add . - To stage the changes made

  10. git commit -m "commit message" - Commit the changes with messages

  11. git restore --staged filename - To unstage the changes made in that file

  12. git log - Shows the history of all the commits

How to remove a commit -

Each commit has an Hash ID. Copy the commit Below ID

git reset Hash ID

Stashing

When a user does not want to commit the changes but at the same time wants to save the changes he made, Stashing is useful.

git stash

git stash pop - To call back the changes

git stash clear - To clear the stashed changes

Linking Git and Github

git remote add origin URL_of_github_repo - Links Git and GitHub

git push origin master - To push the changes into Github Repo

***Git Branches - ***

Git branches are effectively a pointer to a snapshot of your changes.

What is a head?

Head is a pointer that indicates that the changes will be affecting that particular branch.

git branch branch_name - Creating a branch

git checkout branch_name - Move the header to a new branch

**Contributing on GitHub - **

Go to the project and 'Fork' the repository to copy it to your own account

git clone url_of_repo - To clone the repository on your own system

How to delete a commit from GitHub? -

First Delete the commit from Git then,

git push origin (branch) -f

What is Upstream URL?

The link from where the repo has been forked.

git remote add upstream URL

What is a pull request?

Request to merge our branch with the organization branch.

How to sync the main branch of the organization into the forked repo?

git pull upstream main

Squashing your commits

Squashing allows you to combine multiple commits in your branch's history into a single commit.

git branch branch_name

git rebase -i commit_ID

What are merge conflicts?

When many people make the same line changes and create a pull request

Latest Edit-

git init

git add README.md

git commit -m "first commit"

git branch -M master

git remote add origin https://github.com/mainak0907/FOSSMeetup.git

git push -u origin master