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
To Setup your Git for the first time -
$ git config --global user.name "your_name"
$ git config --global user.email your_email
Git Commands -
ls
- Lists the folders insidemkdir foldername
- Makes a foldercd folder
- Takes the control inside the foldergit init
- Initializes a hidden repository inside the folderls -a
- shows the hidden filesls .git
- shows all the .git filetouch filename
- Creates a new filegit status
- Shows the history of the changesgit add .
- To stage the changes madegit commit -m "commit message"
- Commit the changes with messagesgit restore --staged filename
- To unstage the changes made in that filegit 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