Most Common Git Commands

, , Leave a comment

git branch -b new_feature
git branch –no-merged # show the branches that are not merged yet.
git merge –no-ff new-feature -m “merge new-feature branch”
git branch -D new-feature # delete the working branch after merge is completed

 

Working with GitHub

create a GitHub repo hello-remote

git clone <URL for hello-remote>
git clone https://github.com/hydrogeologist/hello-remote.git
git status

add a demo file in local clone, demo.txt

git add demo.txt
git commit -m “added a demo file”

git push -u origin master # now upload the file to the GitHub.

git fetch origin # use this to update the local clone of the remote repository. This let us know how many commits have been made since the last pull
git remote -v # shows the branch on the remote location.

git pull # use this command to update the local repo. (Behind the scenes, git pull is actually a git fetch followed by a git merge)

Coll flag for git diff:

git diff –color-words

Try this feature.
git branch –merged : shows all of the branches that are merged.

Take a look at the diff between branches:
git diff master..branch_name

Rename a branch in Git
git branch -m old_branch_name new_branch_name
git branch –move old_branch_name new_branch_name

Delete Branches
git branch -d branch_name
git branch –delete branch_name

if there are changes in the branch that is not merged yet, we must use D
git branch -D branch_name # forced delete

 

Leave a Reply