So, to do our development work, let us create a new local dev branch as shown below. # git branch -aĪs you see from the above output, there is no additional local or remote branch except the master branch.įor more details on git branch command, refer to this: 15 Git Branch Command Examples to Create and Manage Branches The following commands displays all available branches for this repository (both local and remote). Your branch is up-to-date with 'origin/master'. # git clone By default, the current working branch is master branch. In the following example, I’ve cloned demoproject from remote git repository to work on it locally. # Finally, delete dev branch both locally and remoteįor explanation and example output of the above steps, read the rest of the article. Git commit -m "Made the change." index.html Git clone # Create new dev branch, do your work, and commit changes locally Instead, try running git branch -r to see any remote branches, so you can pick the one you want to git reset from.For the impatient, here is the code snippet for the above steps: # Clone the git repo: If you can’t find origin/master, you may now have that branch on your origin. Now your local changes will be backed up on the branch my-backup-branch, and all remote changes will be forced into your master branch. This will force overwrite any local changes you made.Īnd you’re done. You can see all other branches available to switch to by running git branch -list.įinally, we use git reset -hard origin/master to force git pull. If it’s called something else, you will have to use that command. Then we switch back to our main, master branch, assuming your main branch is called master. If you don’t commit your changes to the backup branch, you will lose them. After that, I’ve added in a commit, so that we commit any changes on that backup branch, my-backup-branch, so the contents remain saved. Then, git branch my-backup-branch creates a new branch, which we switch to for the backup. The other commands are to ensure you don’t lose any data, by making a backup!įirst, git fetch -all syncs up our remote to our local. The key command to force a git pull from a remote repository is git reset -hard origin/master. To force a git pull, we run the following commands to create a backup branch, and then force the git pull on the master branch: If you do not commit/backup your local changes to another branch, they will be overwritten so please be careful. You can also copy your files somewhere else if you’re worried about overwriting them. The important thing to do here is a backup, where you commit all your local changes to a backup branch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |