Skip to content

arpit456jain/Getting-Started-with-open-source

Repository files navigation

Step-by-Step Guide for beginners for getting started with Open-Source

This project is part of Hacktoberfest'21

Hacktoberfest

What is Git and Github?

Git helps is maintaining the history of the project. It maintains a record of what changes were made to a project , when and by whom.
Github is an online platform that hosts git repository.(Repository is a folder which saves all changes).

What is HacktoberFest?

Hacktoberfest is an open-source competition open to everyone in our global community. Whether you’re a developer, student learning to code, event host, or company of any size, you can help drive growth of open source and make positive contributions to an ever-growing community. All backgrounds and skill levels are encouraged to complete the challenge.

  1. Hacktoberfest is a celebration open to everyone in our global community.
  2. Pull requests can be made in any GitHub-hosted repositories/projects.
  3. You can sign up anytime between October 1 and October 31.

Rules:

To earn your Hacktoberfest T-Shirt or tree reward, you must register and make four valid pull requests (PRs) between October 1-31 (in any time zone). PRs can NOT be made to any public repo on GitHub, maintainers have to opt in with the topic Hacktoberfest on the repo. If a maintainer reports your pull request as spam or behavior not in line with the project’s code of conduct, you will be ineligible to participate. This year, the first 70,000 participants who successfully complete the challenge will be eligible to receive a prize.

Projects in which you can contribute:

  • Any github repository with the Hacktoberfest topic
  • For the sake of convenience, you can contribute to this very project :)

Here The Contribution Begins💻

If you are a beginner then this repository is for you. By this tutorial you are going to learn how to make your First Pull Request for sure.

⭐ STAR THIS REPOSITORY THIS WILL PAY OFF MY WORK


1. The first thing you need is Git installed on your system, if it is not installed then download it as per your OS and install it.

Git Setup :-

  • Download Git as per your OS.
  • Git installation Video for Windows User
  • Git installation Video for Mac User
  • Git installation Video for Linux User
  • Install Git
  • Open the Git Bash ( Right Click )
  • Run the Commands
  • $ git config --global user.name "Your Name"

    $ git config --global user.email [email protected]

    $ git config --list

  • You should be able to see your entered name and email under user.name & user.email


2. You should have an account on GitHub if you you don't have an account then simply make it.

3. You will need a text editor accoring to your comfort , I prefer Vs code

Other Text Editors

4. Now you just have to setup the project from GitHub to your local system.

Setting Project on your Local System :-


  • Fork this Repository or Project
  • This will create a copy of this repository in your account.


  • Copy the link of the Repository



  • Open Git bash where you want to clone the project and clone it
  • Clone it
  • Run Command and Hit Enter
    git clone <the link you just copied>
    



    In this case it is
    git clone https://github.com/arpit456jain/Getting-Started-with-open-source.git

  • After you hit enter you will notice that some downloading will start. It's actually cloning of repo form your GitHub repository to your local system.

  • After this you will notice a folder is created with the name of repository



  • Then just close the Git bash and open this folder in your preferred text editor...

  • Here is an example in VS Code.



5. Now Make necessary changes and commit them , lets say you have to add your name in readme , you already set up the project in local system . Now before starting your work always rembember to pull latest change from the main Repo.

  • Fetch And Merge



  • Pull these changes in your local system

  • ``` git pull origin master ```

    The same command can also be divided into the following -
    1. Fetching all commits from upstream
    git fetch --all --prune
    2. Reset the main branch of origin to upstream
    git reset --hard upstream/main



  • make a new branch and then make the changes , then commit them. make sure to commit to the new branch
    Never commit in master branch
  • git checkout -b new_branch_name
    git add -A
    git commit -a -m "message"
    
  • After commiting your changes on your local host you have to push that changes to GitHub , make sure you push the new branch
  • git push origin new_branch_name
    

6. Make the Pull Request

  • when you push the changes you will notice a new branch will be created on GitHub and there will be a green button for creating pull request. Click on it.



  • After this a new page will be open like this


  • Now add a title and description of your PR and click on create pull request.

  • Congrats 🎉 your Pull Request is created




Some Common Error And Their Solutions

1. Updates were rejected or failed to push some refs.


This is most common error you will find and its pretty easy to solve .


Solution: You just have to pull latest changes to your local system first and then you can push them

git pull origin master

Note : if your repo is a forked one and its some commit behind then first fetch n merge then pull changes

2. Unable to detect identity.


Its pretty easy to solve .


Solution: You just have to write your username and email

git config --global user.name "Your Name"
git config --global user.email [email protected]

3. Remote origin already exists.


It is easy to solve


Solution: You just have to update the URL of the remote repository with the name "origin" to the URL of the remote repository you want to add

git remote set-url origin <repository url>

3. Refusing to merge unrelated histories.


This error appears when some of your ambiguous actions confuse Git on how to function further.


Solution: The solution to this fatal error is to use –allow-unrelated-histories flag with the git pull command or git merge command.

git pull origin master –allow-unrelated-histories

3. OpenSSL SSL_read: Connection was reset.


This is the SSL certificate of the server that has not been signed by a third party, so an error is reported.


Solution: This error is most likely caused by network instability and connection timeout.

git config http.sslVerify "false"



4. It is always best to make a new branch.



NEVER commit on the main branch.

The importance of adding a new branch is that we can work on the code until our changes are finalized. Suppose you are working on a project that needs x changes. It will be easier for the maintainer to review changes one at a time instead of all the changes in a single PR. The maintainer can easily suggest changes in your PR on a particular issue.

After finalizing and completing the code, the branch can be merged with the main branch.
1 branch can only have one PR.


Common Git Commands you should know!!!

1. Git checkout

  • You can use the checkout command to switch the branch that you are currently working on.
  • git checkout <branch name>
    
  • You can use the checkout command with `-b` to create a new branch and switch to the same.
  • git checkout -b <branch name>
    

    2. Git init

  • This is the command you need to use if you want to start a new empty repository or to reinitialize an existing one in the project root. It will create a .git directory with its subdirectories.
  • git init <repository name>
    

    3. Git diff

  • You can use this command to see the unstaged changes on the current branch.
  • git diff
    
  • If you want to see the staged changes.
  • git diff --staged
    
  • Or you can compare two branches:
  • gif diff <branch1> <branch2>
    

    4. Git add

  • This is the command you need to use to stage changed files. You can stage individual files.
  • git add <file path>
    
  • You can also stage all files.
  • git add .
    

    5. Git branch

  • Using git branch will list all the branches of the repository.
  • git branch
    
  • Or you can use it to create a new branch, without checking it out.
  • git branch <new branch>
    
  • To delete a branch.
  • git branch -d <branch name>
    

    6. Git log

  • If you want to see what you have committed till now.
  • git log
    
  • If you want to see last 5 commits among 100000 commits.
  • git log -p -1
    

    7. Git merge

  • Merge the changes made in a staging branch into the stable branch.
  • git merge <branch_name>
    

    8. Git rm

    Remove files or directories from the working index (staging area). With git rm, there are two options to keep in mind: force and cached. Running the command with force deletes the file. The cached command removes the file from the working index. When removing an entire directory, a recursive command is necessary.

  • To remove a file from the working index (cached)
  • git rm --cached <file name>
    
  • To delete a file (force)
  • git rm -f <file name>
    
  • To remove an entire directory from the working index (cached)
  • git rm -r --cached <directory name>
    
  • To delete an entire directory (force)
  • git rm -r -f <file name>
    

    9. Git stash

    To save changes made when they’re not in a state to commit them to a repository. This will store the work and give a clean working directory. For instance, when working on a new feature that’s not complete, but an urgent bug needs attention.

  • Store current work with untracked files
  • git stash -u
    
  • Bring stashed work back to the working directory
  • git stash pop
    

    10. Git clear

  • To clean git bash.
  • git clear
    

    Git Cheatsheet!!!

    SETUP

    Configuring user information used across all local repositories

    1. git config --global user.name “[firstname lastname]”

  • set a name that is identifiable for credit when review version history
  • 2. git config --global user.email “[valid-email]”

  • set an email address that will be associated with each history marker
  • 3. git config --global color.ui auto

  • set automatic command line coloring for Git for easy reviewing

  • SETUP & INIT

    Configuring user information, initializing and cloning repositories

    1. git init

  • initialize an existing directory as a Git repository
  • 2. git clone [url]

  • retrieve an entire repository from a hosted location via URL

  • STAGE & SNAPSHOT

    Working with snapshots and the Git staging area

    1. git status

  • show modified files in working directory, staged for your next commit
  • 2. git add [file]

  • add a file as it looks now to your next commit (stage). This area contains a list of all the files you have recently changed. It tells Git that you want to include updates to a particular file in the next commit.
  • 3. git reset [file]

  • Remove the specified file from the staging area, but leave the working directory unchanged. This unstages a file without overwriting any changes.
  • 4. git diff

  • diff of what is changed but not staged
  • 5. git diff --staged

  • diff of what is staged but not yet commited
  • 6. git commit -m “[descriptive message]”

  • commit your staged content as a new commit snapshot

  • BRANCH & MERGE

    Isolating work in branches, changing context, and integrating changes

    1. git branch

  • list your branches. a * will appear next to the currently active branch
  • 2. git branch [branch-name]

  • create a new branch at the current commit
  • 3. git checkout

  • switch to another branch and check it out into your working directory
  • 4. git merge [branch]

  • merge the specified branch’s history into the current one

  • INSPECT & COMPARE

    Examining logs, diffs and object information

    1. git log

  • show the commit history for the currently active branch
  • 2. git log branchB..branchA

  • show the commits on branchA that are not on branchB
  • 3. git log --follow [file]

  • show the commits that changed file, even across renames
  • 4. git diff branchB...branchA

  • show the diff of what is in branchA that is not in branchB
  • 5. git show [SHA]

  • show any object in Git in human-readable format

  • SHARE & UPDATE

    Retrieving updates from another repository and updating local repos

    1. git remote add [alias] [url]

  • add a git URL as an alias
  • 2. git fetch [alias]

  • fetch down all the branches from that Git remote
  • 3. git merge [alias]/[branch]

  • merge a remote branch into your current branch to bring it up to date
  • 4. git push [alias] [branch]

  • Transmit local branch commits to the remote repository branch
  • 5. git pull

  • fetch and merge any commits from the tracking remote branch


  • What if I have Merge Conflicts?

    A GitHub conflict is when people make changes to the same area or line in a file. This must be fixed before it is merged in order to prevent collision in the main branch.


    Now just make a Pull Request and add your name in Read me file.

    CodeSmashers Community

    Project Admins ❤️


    Arpit Jain

    ✨ Contributors

    Thanks go to these Wonderful People 👨🏻‍💻: 🚀


    Contributions of any kind are welcome!

    Open Source Programs click here

    Some Open Source Projects you can contribute to.

    Project Name Tech Stack
    PixelVibe HTML , CSS , Bootstrap , Java Script , Python , Django
    Cool Front-End Templates HTML , CSS , Bootstrap
    Amazing Css effects HTML , CSS , Bootstrap
    Amazing Js Projects HTML , CSS , Bootstrap, JS
    Web-Development-Path-And-Resources Documentation
    Open-Source-Programs documentaion

    show some ❤️  by giving the star to this repo