Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Git - Is just this.

Tags: branch push stash

First install Git. Google will tell you that. Clone the project that you want to work on using command:git clone It is recommended to create new branch before you start coding:git checkout -b Question 1: My colleague created a branch and pushed but couldn't get that in my local. How can I do that?Use below command to fetch changes from remote.git fetchthen try checking out to the branch that your colleague shared asgit checkout You have done some changes and want to push them to your branch then follow below steps:git add -A // to add all changes called staginggit add // to add file by file.it is an optional - git reset // if you want to avoid pushing any filegit commit -m "" // to commit git push // to push to your repository.Question 2: My colleague and I are working on same branch. We are pushing our changes as soon as we are done. How we can manage to not to miss any of our changes while pushing?Best way: Avoid.Approach 1: Always pull latest changes from branch (which have been pushed by your colleague) and resolve any conflicts and push all of your changes. Question 3: I did couple of changes but I don't want to push them as of now for some reason but need these details to be present somewhere. How can I achieve it?Best Way: Push your changes to separate branch and remember that branch name.Approach 1: You can use stashing feature of git to temporarily stash the changes and apply whenever required. Below commands are useful for same purpose:git stash // whatever changes you did so far are stashed. git stash apply // to apply stashed changes whenever you need.git stash apply stash@{1} // to apply first record of stash.stash stores all the stashed files like a stack. By default 0th item is applied as soon as you hit git stash apply but if you want specific record of stash then specify that number and apply like shown above.I stashed some changes and forgot what changes I did then how can see them without applying those changes.You can use below command:git stash show // shows the list of changed files from recent stashgit stash show -p // shows changes in files**Question 4: **What are all possible push rejections?You remote branch has new changes that your local doesn't have that means your colleague has pushed few changes to your branch.so, as mentioned - pull his changes first and then apply changes and push all changes together. You might not have permission to push. Check admin to get access. Question 5: I want specific changes of one commit of some other branch in my current branch. How Can I achieve that?Using cherry-pick as:git cherry-pick Question 6: How can I merge my changes with master branch before creating pull request(PR)?Several ways are there:git pull origin mastergit merge mastergit rebase masterResolve any merge conflicts and push. Done. There were several other features that git provides. Just read carefully the error or exception you see while using git. Search the same error in Google. Done.I covered mostly used commands in this article and is pretty much enough to do day to day activities of Dev.Please do comment if I miss any.Thanks.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Git - Is just this.

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×