git-branch

What is the difference between origin and upstream on GitHub?

人盡茶涼 提交于 2019-11-25 23:17:31
问题 What is the difference between origin and upstream on GitHub? When a git branch -a command is done, some branches have a prefix of origin ( remotes/origin/.. ) while others have a prefix of upstream ( remotes/upstream/.. ). 回答1: This should be understood in the context of GitHub forks (where you fork a GitHub repo on GitHub before cloning that fork locally). upstream generally refers to the original repo that you have forked (see also "Definition of “downstream” and “upstream”" for more on

Move the most recent commit(s) to a new branch with Git

烂漫一生 提交于 2019-11-25 23:06:52
问题 I\'d like to move the last several commits I\'ve committed to master to a new branch and take master back to before those commits were made. Unfortunately, my Git-fu is not strong enough yet, any help? I.e. How can I go from this master A - B - C - D - E to this? newbranch C - D - E / master A - B 回答1: Moving to an existing branch If you want to move your commits to an existing branch , it will look like this: git checkout existingbranch git merge master # Bring the commits here git checkout

How to remove local (untracked) files from the current Git working tree

旧街凉风 提交于 2019-11-25 22:58:19
问题 How do you delete untracked local files from your current working tree? 回答1: As per the Git Documentation git clean Remove untracked files from the working tree Step 1 is to show what will be deleted by using the -n option: # Print out the list of files which will be removed (dry run) git clean -n Clean Step - beware: this will delete files : # Delete the files from the repository git clean -f To remove directories, run git clean -f -d or git clean -fd To remove ignored files, run git clean

Can I recover a branch after its deletion in Git?

点点圈 提交于 2019-11-25 22:48:54
问题 If I run git branch -d XYZ , is there a way to recover the branch? Is there a way to go back as if I didn\'t run the delete branch command? 回答1: Yes, you should be able to do git reflog and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha] . And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there. Credit to @Cascabel for this condensed/one-liner version. You can do it in one step: git checkout -b

Default behavior of “git push” without a branch specified

可紊 提交于 2019-11-25 22:44:05
问题 I use the following command to push to my remote branch: git push origin sandbox If I say git push origin does that push changes in my other branches too, or does it only update my current branch? I have three branches: master , production and sandbox . The git push documentation is not very clear about this, so I\'d like to clarify this for good. Which branches and remotes do the following git push commands update exactly? git push git push origin origin above is a remote. I understand that

How to clone all remote branches in Git?

寵の児 提交于 2019-11-25 22:01:11
问题 I have a master and a development branch, both pushed to GitHub. I\'ve clone d, pull ed, and fetch ed, but I remain unable to get anything other than the master branch back. I\'m sure I\'m missing something obvious, but I have read the manual and I\'m getting no joy at all. 回答1: First, clone a remote Git repository and cd into it: $ git clone git://example.com/myproject $ cd myproject Next, look at the local branches in your repository: $ git branch * master But there are other branches

How do I delete a Git branch locally and remotely?

泪湿孤枕 提交于 2019-11-25 21:40:35
问题 I want to delete a branch both locally and remotely. Failed Attempts to Delete Remote Branch $ git branch -d remotes/origin/bugfix error: branch \'remotes/origin/bugfix\' not found. $ git branch -d origin/bugfix error: branch \'origin/bugfix\' not found. $ git branch -rd origin/bugfix Deleted remote branch origin/bugfix (was 2a14ef7). $ git push Everything up-to-date $ git pull From github.com:gituser/gitproject * [new branch] bugfix -> origin/bugfix Already up-to-date. What should I do