git-checkout

Add / commit a file to all branches

萝らか妹 提交于 2021-02-17 05:22:09
问题 Say I am on a branch and the index is dirty. I made changes to a file x, and I have some other changes too. Is there a way to add file x to all existing branches? Something like this: #!/usr/bin/env bash current_branch="$(git rev-parse --abbrev-ref HEAD)" git add . git commit -am "added x" git fetch origin git for-each-ref --format='%(refname)' refs/heads | while read b ; do git checkout "$b" git checkout "$current_branch" -- x done git checkout "$current_branch"; # finally, check out the

Is `pull` needed after checking out a new branch?

╄→尐↘猪︶ㄣ 提交于 2021-02-07 13:31:42
问题 In case of a git-project with several branches, the question is when you checkout a new branch (first time), is a git pull needed ? $master> git checkout branchA $branchA> git pull Note that the idea here is that both commands are executed right after each other (this question is not about when-or-why you should run git pull ) I've tested this, but so far the pull doesn't pull in new commits, but some people claim that the pull is needed. Can someone describe a scenario in which this is

Is `pull` needed after checking out a new branch?

非 Y 不嫁゛ 提交于 2021-02-07 13:28:15
问题 In case of a git-project with several branches, the question is when you checkout a new branch (first time), is a git pull needed ? $master> git checkout branchA $branchA> git pull Note that the idea here is that both commands are executed right after each other (this question is not about when-or-why you should run git pull ) I've tested this, but so far the pull doesn't pull in new commits, but some people claim that the pull is needed. Can someone describe a scenario in which this is

Creating aliases for Git branch names

孤人 提交于 2021-02-07 07:36:34
问题 Suppose I have the following branches in git: master release-2014-11-02-some-long-text I would like to easily switch between those to, like this: git checkout devel # checkout to master git checkout release # checkout to the branch release currently points/aliases to, in this case: release-2014-11-02-some-long-text (I would like to change this alias from time to time) How can I do that in Git? 回答1: You can try using git symbolic-ref (as mentioned in "Is it possible to alias a branch in Git?")

Shallow clone cannot fetch new commits/branches?

一个人想着一个人 提交于 2021-02-05 12:18:07
问题 I have this: git clone --depth=1 <repo> app cd app git fetch origin git checkout a119b1076dd45a88a3609c4f7893ef3d82f9a4ee but it says: fatal: reference is not a tree: a119b1076dd45a88a3609c4f7893ef3d82f9a4ee if I use the name of the branch: git checkout me/work I get: error: pathspec 'me/work' did not match any file(s) known to git. is it because I did a shallow clone? don't make much sense to me. The commit is on the remote, at the very least the branch/commit with that name is on the remote

How can i copy a file from local commit on a different branch?

旧巷老猫 提交于 2021-02-05 06:51:28
问题 I committed a file on master branch but not pushed remote . Now i am working on feature branch and i want that file to be copied to feature branch from master branch. How can i do this? 回答1: You can checkout a specific file from another branch: git checkout master -- path/to/file The file will be copied from the branch as is into the working tree, and automatically staged. Note that the relative path from the working tree root is important. For example if you are in the root of the working

Can I make git automatically update submodules when checking out a branch?

▼魔方 西西 提交于 2021-02-05 05:34:05
问题 I'm working on a git repository with some submodules, which have different revisions on different branches. When I switch branches, I get a: M path/to/subrepo Switched to branch 'another-branch' message. I then manually do: git submodule update --recursive and that goes away. I tried writing a git hook, in .git/hooks/post-checkout: #!/bin/bash exec git submodules update --recursive but this doesn't seem to do anything. I tried to add an exec echo hello from post-hook line - doesn't seem to

Git Development-Test-Production branches proccess [closed]

醉酒当歌 提交于 2021-02-04 21:08:08
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 10 months ago . Improve this question I am interesting in this process: First I'd like to make any in my development branch , than it should be pushed to Test (master) branch and, therefore, to production . For me the process: init commit then, make prod branch from master init commit then

Hey git, what happened to the last commits?

给你一囗甜甜゛ 提交于 2021-01-28 05:20:43
问题 I just used check out head after making a commit. I figured that doing this checkout would not actually do anything, but I seem to have been wrong. It put me into a 'detached head' state. I ignored this note, and continued to make a few additional commits. The message change to 'Head detached from ...' Feeling a bit annoyed by this, I looked for a way to fix it. The answer I found was git checkout master . I did this and now my last few commits disappeared. What happened here? 回答1: TL;DR Use