Last Updated on January 30, 2021 by sandeeppote
Changes committed to local or remote repository needs to be synced.
To get the remote repository synced with local use fetch and push vise versa.
git fetch origin branch_name
When a fetch is done it creates or brings in changes from remote to origin/branch_name in local but not merge with local branch. For this we need to merge the changes to the local branch
To see the origin branch-
git branch -r
Use these strategies for fetch-
Fetch the changes often
Fetch before you start the work
Fetch before you push the changes so that any conflicts can be resolved.
To Merge the changes to the local branch or the working branch first checkout the branch where you want to merge and then use following-
git merge origin/branch_name
You may also use git pull
git pull = git fetch + git merge
To pull the changes again switch to the local branch you want to merge the changes to-
git pull origin branch_name
Push changes to remote
You may use following-
git push origin remote_branch_name
This command shall push changes from source local branch into origin target branch
You may also use this –
git push origin source_local_branch:target_remote_branch
Note this is separated by :(colan)
Delete remote branch
To remove remote branch simply use –
git push origin :target_remote_branch
Note there is nothing before : here which means push nothing to target remote branch which shall delete that branch.
OR use following to delete remote branch-
git push origin --delete remote_branch