Recently I started contributing to open source so learned some of the most important basic required commands and I may miss many commands but I would like to share what are the mostly used ones.
Before starting we have to initialize git in the folder where we want git to track our progress by git init
Git for open source
1. Fork the repo to our git hub profile
2. Cloning some one else repo our local editor
git clone URL
URL is terminated by .git in code section of repository
3.Creating separate branch for cloned repo
git branch Goutham Goutham here is branch name and we need to switch to Goutham branch by git checkout Goutham
4.Committing changes
git add . and git commit -m "message"
5. Pushing changes
I observed many times by git push this command directly pushes to others repo and they review our code.
If we want to make Pull Request Here what we have to do
1.git remote add Goutham2 URL Here URL is link for our forked repo and Goutham2 is the name given to URL
- git push Goutham2 Goutham Here we are pushing Goutham branch to Forked repo
3.We need to make necessary PR
For different Pull requests we require different branches it would be difficult for the reviewer.
Basic Commands
1 . git branch
Used to create different branches by git branch Name, Name is branch name
2. git log
Used to display different commit histories like this
and IDs are associated with commits
3. git reset
Most useful git command , through this command though we have committed many times we can make our
project how it was before by git reset ID , now our project looks like how it was at this commit.
4. git stash
When we did git reset by using git stash only we observe changes as our project is now in unstaged area by this we can bring back to staged area this can also be used when we unknowingly deleted some files .
Problems I faced while using git
1 . When we want to push changes to our existing project Error would be
Here we need to force push this by git push -f origin main
- Different Commit Histories
I don't know why this occured but I know when this error occurs
when we want to push our remote branch to our repo by git push Goutham2 Goutham
Here we are pushing Goutham branch of our project to Goutham2 repo and if we want to merge Goutham with main/master we see this error
I don't understand this error , but I am mentioning If you know please explain I've been struggling with this error
These are the git commands I learned recently So please mention if I missed any most important commands.
If you found anything wrong with my blog please let me know
Thanks for reading ...