This cheat sheet summarizes commonly used Git command line instructions for quick reference
Story 1: What will we do when we have to work on a new features/ new work?
First, we need to checkout master branch “$git checkout master” . Then we will get the latest update. So we will run “$git pull” . Now our master branch is up to date.
This time to create we will create our working branch for new features/ new work. We will run “$git checkout -b 123-new-features”. Here we keep an identifier/ ticket id in prefix on our branch name for future reference.
Finally, we are now in our new branch and we will push this new branch in remote using “$git push –set-upstream origin 123-new-features” command. After completion of this command we will get our branch in remote repository.
In this point, we will write our code. For that we may add new files/ change existing file. So, how will we push our update and how will we know what files have made the changes?
We can run “$git status” to know what the changes we have made and then we need to add the changes file using “$git add <file>” command. Here we need to add commit for pushing our update to remote remote repository.
The command of the commit : $ git commit -m “add ….. features”. after this run the push command : $git push
Story 2: How will we merge “123-new-features” branch to master branch?
It’s pretty simple if we don’t have any conflict. In case of conflict – I will write another post. First we need to checkout master branch (run $git checkout master).
After checkout the we need to run merge command: $git merge 123-new-features
Finally, we need to commit and push the merging update.
Later I will write some different stories so that we can understand when and how we will use git.
Git cheat sheet
To know Changed files in your working directory
$ git status
To add changes file
$ git add <file>
To add comment file
$ git commit -m "<comment here>"
Push local changes to remote
$ git push
Pull the remote update to local
$ git pull
For creating new branch and check newly created branch
$ git checkout -b <new-branch-name>
Push newly created local branch to remote
$ git push --set-upstream origin <new-branch-name>
For clearing all changes and back to previous commit
$ git stash
Reset local branch
$ git reset --hard origin/<branch-name>