Important Git commands

- git pull --rebase
To fetch the fresh data into the local branch, that was merged by someone else after you took the
clone or previous pull.

- git rebase --abort
If for any reason like conflict, you don't want to revert the rebase from your local branch

- git rebase --continue
If you have resolved the conflicts which you encountered while rebasing then wants to continue the rebase

- git commit --amend 
If you want to add or edit files or edit comments into the existing commit
To edit and save the message :wq! in the vi editor
If there is no change in the message then use :q!

- git push origin HEAD:refs/for/master
If you want to push to review branch before pushing to actual master

- git push origin HEAD:refs/drafts/master
If you don't want to merge into the master and the work is in progress then you can push the commit to draft.
Later on click on publish through UI to move it to Needs Code-Review Label.

- git add .
To add all the added/modified/deleted files from the current directory that needs to be committed

- git commit -m "commit message"
To commit the files locally

- git status
To check the status

- git checkout -b <name of the branch>
-b option allows you to create a new branch and checkout the same with a single command

Note: If we try to rebase the newly created branch then we will get the below error
"There is no tracking information for the current branch."

Please specify which branch you want to rebase against.
So need to set the remote branch like below
git branch --set-upstream-to=origin/<remote-branch> <new-branch>

- git checkout <name of the branch>
To just switch the branch use the above command without -b option like

- git branch
To list all the branches that was created by you and also show the current working branch

- git branch -a
To list all available branches

- git fetch
To check if there are any incoming changes

- git apply <patchsetid.diff>
To apply a downloaded patchset

- git apply -R <patchsetid.diff>
To revert the applied patch set but note there should not be any local changes on the same files

- git credential-osxkeychain erase
To erase the saved password in MAC

- git commit -a
This is the last step when we are merging conflicts.

- To clone a specific branch
git clone <repo-url>
git checkout -b <branch-name>
git pull origin <branch-name>

- git cherry-pick -n {commit-id}
This allows applying a given commit of any branch onto the current branch without committing.

- git cherry-pick  {commit-id}
This allows applying a given commit of any branch onto the current branch with committing the changes.

Comments

Popular Posts