How to reset and sync local git repository with remote branch?

If you are looking a command to destroy/reset any local changes in your current git repository then below are the steps for you –

Remember to replace origin and master with the remote and branch that you want to synchronize with.

Command –

> git fetch origin && git reset –hard origin/master && git clean -f -d

Or step-by-step-

> git fetch origin
> git reset –hard origin/master
> git clean -f -d

Your local branch is now an exact copy (commits and all) of the remote branch.

We can also add these as an alias in .gitconfig file –

[alias]
resetorigin = !git fetch origin && git reset –hard origin/master && git clean -f -d

Then we can type –

> git resetorigin

 

Programming is easy…

Advertisements

Git commands….

1) Clone repository-

git clone “xyz.git”

2) Add files-

git add “filename.ext” OR *.*

3) Commit files-

git commit -m “message”

4) Push to remote repository-

git push origin master

5) Delete files-

git rm “file-1.txt”    [It deletes from both local and repo]

git rm –cached “file-1.txt”  [It removes only form repo]

6) Delete folder-

git rm -rf “folder name”

7) Status-

git status

8) Pull from remote repository-

git pull –all