Git Cheat Sheet – A Collection of the Personal Git Cmds

author-avatarRAJESH, July 14, 2020

Git cheat sheet Opensource contribution

//your repository

$ git clone git@github.com:Your_Repository_URL.git

//if you are cloning a forked repository of someone || This step is optional only follow if you are contributing to other repos
// add upstream/parent/original repository as upstream repository

$ git remote add upstream git@Repository_URL

ex: $ git remote add upstream git@zend/zend-validator.git

//do some changes and then

$ git checkout master/develop/or_specified_branch
$ git pull upstream master && git push origin master
$ git checkout -b hotfix/readme-update

//-b to create a new branch if you have a local branch already then don't use -b

//hotfix = new branch name or we can say prefix like: bugfix/hotfix/feature extra /readme-update : detailed-name
//you should create a new branch or checkout to the local branch you already created. Directly commit to master or other main branch is not recommended.

//-u to also push to the upstream directory so we can create a pull request later in the original repository

$ git push -u origin hotfix/readme-update

//got to GitHub dashboard and generate the pull request follow the proper format of the pull request.

//if your branch is behind with the branch you want to commit let’s say you want your commit to merge to master or develop branch and your hotfix/readme-update is 3 commits behind then you
// have to Rebase your current branch with parent branch.

//Rebase commands

//first Checkout to the main branch it could be master or develop branch

$ git checkout branch-name

$ git pull -v

//again Checkout to your local branch ex: Feature/my-local-branch

$ git checkout local_branch_name

//now Rebase it with parent branch

$ git rebase -i develop/master/or-your-branch-name

//if you got merge conflict while Rebasing with parent branch you have to resolve all merge conflict.

***********Rebase Step***************

//Edit all suggested files by git and then again do `git status` command to check changed files. Now follow below commands

$ git add files_names
$ git rebase --continue

// if you get more conflicts then resolve again and repeat from `Rebase Step`

//if Rebase success then do git push. Force the push. If the repository is forked then include -u to also push to origin repository

$ git push origin Local/branch_name --force

All Done if you are pushing to a repository you’re forked from somewhere then you can see the create pull request option will be enabled.

Share It If you like It.

< PrevPost NextPost >

Start a project

Interested in working together? We should
queue up a chat. I’ll buy the coffee.

Living, learning, & leveling up
one day at a time.

Handcrafted by me © RJ21 Nagour alaa😅

Made with ♥ by

Copyright © Rajesh Royal 2021.