Understanding git fetch command
git fetch origin
git fetch command only downloads new data from a remote repository , origin refers to fetch data from remote repository .It doesn’t integrate any of this new data into your working files. Fetch is great for getting a fresh view on all the things that happened in a remote repository.
Understanding git pull command
git pull origin
git pull, is used to update your current HEAD branch with the latest changes from the remote server.This means that pull not only downloads new data; it also directly integrates it into your current working copy files.
“git pull” tries to merge remote changes with your local ones, a so-called “merge conflict” may occur.
Like for many other actions, it’s highly recommended to start a “git pull” only with a clean working copy. This means that you should not have any uncommitted local changes before you pull.
Understanding git push command
git push origin node1
A local branch that you create on your machine is kept private to you until you explicitly decide to publish it.
origin refers to remote repository and node1 refers to branch in which you want to publish the data. push command tells Git to publish our current local HEAD branch on the “origin” remote under the name “node1” (it makes sense to keep names between local branches and their remote counterparts the same).
If work of the nay branch is done and we have already merged it with our master , we can delete the branch with simple command below.
git branch -d node1
we also delete the remote branch by using the “git push” command with the “–delete” flag
git push origin --delete node1
Checking list of existing remotes branches
Be a little more verbose and show remote url after name.
git remote -v
With no arguments, shows a list of existing remotes.
Adding a remote
To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at.
he git remote add command takes two arguments:
A remote name, for example, origin
A remote URL, for example, https://github.com/user/repo.git
git remote add origin https://github.com/user/repo.git
Moving file from staging area to unstaged area
Many times files you wanted to be in working copy goes to staging area , get rid of the files those are stuck in staging area with this simple command.
git reset HEAD index.html