Difference between revisions of "Git Cheat Sheet"
Jump to navigation
Jump to search
(5 intermediate revisions by the same user not shown) | |||
Line 25: | Line 25: | ||
$ git checkout master # switched to branch master | $ git checkout master # switched to branch master | ||
$ git merge [branch_name] # merge | $ git merge [branch_name] # merge | ||
+ | |||
+ | '''Reset Local Branch Same As Remote Branch ''' | ||
+ | |||
+ | $ git checkout [name_of_branch] # checkout to branch that will be reseted | ||
+ | $ git reset --hard origin/[name_of_branch] # reset to be same as remote branch | ||
+ | $ git reset --hard origin # reset local master to be same with remote master | ||
+ | |||
+ | '''Reset Branch Same As Master or Other Branch''' | ||
+ | |||
+ | $ git checkout [name_of_branch] # checkout to branch that will be reseted to be same as master | ||
+ | $ git reset --hard master # reset to be same as master | ||
+ | |||
+ | '''Overwrite File in A Working Git Branch from Another Branch''' | ||
+ | |||
+ | $ git checkout [name_of_branch] # checkout to branch where a file need to be replaced or overwrited | ||
+ | $ git checkout [source_branch] path/to/file # source branch where the file will come from |
Revision as of 08:08, 10 February 2021
https://www.earthdatascience.org/workshops/intro-version-control-git/basic-git-commands/
Create New Branch from Master or Other Branch
$ git checkout master # first, we work in master branch $ git pull # pull from original branch $ git checkout -b [new_branch_name] # creating new branch in our local fs $ git push origin [new_branch_name] # push our new branch to Github or Gitlab $ git config core.autocrlf false # stop replacement warning message
Delete Branch in Our Local Filesystem
$ git branch -d [name_of_branch]
or
$ git branch -D [name_of_branch] # force deletion
Delete Branch in Github or Gitlab
$ git push origin :[name_of_branch]
Merge Branch to Master
$ git checkout master # switched to branch master $ git merge [branch_name] # merge
Reset Local Branch Same As Remote Branch
$ git checkout [name_of_branch] # checkout to branch that will be reseted $ git reset --hard origin/[name_of_branch] # reset to be same as remote branch $ git reset --hard origin # reset local master to be same with remote master
Reset Branch Same As Master or Other Branch
$ git checkout [name_of_branch] # checkout to branch that will be reseted to be same as master $ git reset --hard master # reset to be same as master
Overwrite File in A Working Git Branch from Another Branch
$ git checkout [name_of_branch] # checkout to branch where a file need to be replaced or overwrited $ git checkout [source_branch] path/to/file # source branch where the file will come from