Commands and Operation
Remote Master-------------------------------------Remote branch
| |
| |
| |
| |
Local Master ---------------------------------------Local branch
Usual Operations :
- Usually project will be made available in Git
- User clones the repository into local (once you clone master you get all the branches in the repository)
- creates a story branch locally if not available / if available checkout that branch
- Works on development work
- commits the Changes to local branch
- Pushes the changes to remote branch
- Then the code pushed code is merged to master in remote.
Scenario 1: Developer wants to use the new code his colleague merged recently to master.
- Saves current changes in his current branch
- Developer switches to local master
- Perform PULL request to update his local master with latest changes.
- checkout the story branch
- Merges the updated the master to local branch
Scenario 2: Developer completed his coding while merging his code to remote master , he faces merge conflicts.
- checkout master
- pull all the changes from remote master to local master
- checkout story branch
- perform merge
- Solve all the conflicts
- Git shows "AUTO CONFLICT merge xxxx"
- Files turn red (Eg :intelliJ)
- rt ck > Git > resolve conflicts
- click Merge button
- Window with 3 screens open : middle screen - Current code , left and right screen shows the code in local staging and code in master
- Make required selection
- Save
- Commit changes
- Push to story branch
- Raise PR (merge to master)
git checkout master
git pull
git checkout my_branch
git merge master
(now use above conflict resolution to solve the issue )
Clone-Remote Master into local:
Usually any user will either clone the remote repository into his computer or create a local master repository.
git clone git_ssh_link #clone from git
git init #new repository without cloning
Check status:
git branch
Result:
*master
Create / Use already existing branch
once user has cloned / create a local repository
git checkout - b branch_new #Create a new branch in local and switch
git branch branch_new #Just create a new branch in local
Message display / status
git branch #display all branches
git branch -vv #display all branches with their upstream branch
git status #display status of project wrt git
git log
Change branch
git checkout branch_new #switch branch
Commit changes to staging whenever developer has reached a checkpoint
git add file #add file to local staging
git commit -m "description" #commit added file in staging
Push changes to story branch in remote (cloud)
git add file #add file to local staging
git commit -m "description" #commit added file in staging
git push -u origin branch_new #Create new story branch in remote and put changes there
Update the current branch if new changes are available in remote
git pull origin branch_name #1st time only
git pull #get latest updates from remote branch whichever is made upstream else same branch which we are currenlty
Remove the file from local git
git rm -rf file_name #delete file from local git
Reset
git checkout file #reset changes of the current file
git reset #save and reset changes of all the files to last commit
git reset --hard
#reset to last commit without commitingDelete branch
git branch -D branch-name
To Create a upstream
git branch -u masterbranchname # from where u want to pull latest code
Example to create a new project locally and push it to remote :
- git init
- git add README.md
- git commit -m "first commit"
- git remote add origin git@github.xxx.com:username/scala_protobuf.git
- git push -u origin master
…or push an existing repository from the command line
- git remote add origin git@github.xxx.com:username/scala_protobuf.git
- git push -u origin master
Git Remove File from Face of the earth (all history included)
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
git push --all
Git delete remote branch
git push origin --delete branch_name
No comments:
Post a Comment