git-branch

How to add Git's branch name to the commit message?

送分小仙女□ 提交于 2019-11-26 15:47:38
I need some help with a Bash script that will automatically add the git's branch name as a hash in commit messages. ninjagecko Use the prepare-commit-msg or commit-msg githook . There are examples already in your PROJECT/.git/hooks/ directory. As a security measure, you will have to manually enable such a hook on each repository you wish to use it. Though, you can commit the script and copy it on all clones into the .git/hooks/ directory. shytikov Here is my commit-msg script as an example: #!/bin/sh # # Automatically adds branch name and branch description to every commit message. # NAME=$

Does github keep deleted remote branches in history? If so, can those be restored?

拥有回忆 提交于 2019-11-26 15:43:34
问题 I was wondering if there is a way to restore a remote deleted branch in github. History clearly keeps record of the branch and merges with other branches but I'm not sure if it's possible to restore a deleted branch. Thanks. 回答1: Yes, it's possible to restore a deleted branch from git. Find your Commit ID: Search for a branch using git reflog If you had the branch in your local git repo within the last 30 days, you may be able to find it in the reflog using the following: git reflog Search

Move branch pointer to different commit without checkout

落花浮王杯 提交于 2019-11-26 15:34:22
To move the branch pointer of a checked out branch, one can use the git reset --hard command. But how to move the branch pointer of a not-checked out branch to point at a different commit (keeping all other stuff like tracked remote branch)? Adam A N.B. If you simply want to move a branch to another commit, the easiest way is git branch -f branch-name new-tip-commit as detailed by Chris Johnsen's answer . You can do it for arbitrary refs. This is how to move a branch pointer: git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit> The general form: git update-ref

Is there a way to lock a branch in GIT

丶灬走出姿态 提交于 2019-11-26 15:24:35
I have an idea of locking a repository from users pushing files into it by having a lock script in the GIT update hook since the push can only recognize the userid as arguments and not the branches. So i can lock the entire repo which is just locking a directory. Is there a way to lock a specific branch in GIT? Or is there a way an Update Hook can identify from which branch the user is pushing and to which branch the code is pushed? The branch being pushed to is the first parameter to the update hook . If you want to lock the branch myfeature for pushing, this code (placed in hooks/update )

Git undo local branch delete

落爺英雄遲暮 提交于 2019-11-26 14:58:42
问题 I just deleted the wrong branch with some experimental changes I need with git branch -D branchName . How do I recover the branch? 回答1: You can use git reflog to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using git branch branchName <sha1> Edit: As @seagullJS says, the branch -D command tells you the sha1, so if you haven't closed the terminal yet it becomes real easy. For example this deletes and then immediately restores a branch named master2

Git: track branch in submodule but commit in other submodule (possibly nested)

喜欢而已 提交于 2019-11-26 14:39:29
问题 I am looking for a situation in which I have a git structure with (possibly nested submodules). For each of these submodules, I want to specify separately, whether they should track a branch (see e.g., Git submodules: Specify a branch/tag) For instance, my project may look like this: main.tex |- submod1 @ master | |-subsubmod1 @qsdf123 |- submod2 @ master | |-subsubmod2 @shasha12 |- submod3 @ qsdf321 Now, I want a way to update my submodules. git submodule update --recursive will update all

How to restrict access to master branch on git

烂漫一生 提交于 2019-11-26 12:54:44
问题 I have a single repo in which I have 2 user groups: Admins HTML/UI Developers I do not wish to give read/write access of my master branch to my HTML developers as they do not need to work on it and should not be misusing the core code. Though they need to work on their own branch ui-developers . How do I do this on git? P.S.: I am using BitBucket UPDATE: I had posted this question when I was extremely new to coding and git. After 2 years of experience, I now know that git doesn\'t allow to

Create Git branch with current changes

試著忘記壹切 提交于 2019-11-26 12:49:25
问题 I started working on my master branch thinking that my task would be easy. After a while I realized it would take more work and I want to do all this work in a new branch. How can I create a new branch and take all these changes with me without dirtying master ? 回答1: If you hadn't made any commit yet, only (1: branch) and (3: checkout) would be enough. Or, in one command: git checkout -b newBranch As mentioned in the git reset man page: $ git branch topic/wip # (1) $ git reset --hard HEAD~3 #

Git submodule to track remote branch

人盡茶涼 提交于 2019-11-26 12:46:19
问题 I\'m trying to use git submodules for aggregating 10+ repositories into one structure for easy development. It is supposed to clone the module and checkout a branch. Instead, the module is checked out in detached head mode. git clone git@github.com:org/global-repository.git git submodule update —init cd config-framework git status $git status #HEAD detached at b932ab5 nothing to commit, working directory clean gitmodules files seems to be okay $cat .gitmodules [submodule \"config-framework\"]

Push commits to another branch

风格不统一 提交于 2019-11-26 12:33:58
问题 Is it possible to commit and push changes from one branch to another. Assume I commited changes in BRANCH1 and want to push them to BRANCH2 . From BRANCH1 , is it valid to do: git push origin **BRANCH2** And then reset BRANCH1? 回答1: That will almost work. When pushing to a non-default branch, you need to specify the source ref and the target ref: git push origin branch1:branch2 Or git push <remote> <branch with new changes>:<branch you are pushing to> 回答2: Certainly, though it will only work