로컬 지점이 추적하고있는 원격 지점 찾기
로컬 브랜치가 추적하는 원격 브랜치를 어떻게 알 수 있습니까?
git config
출력 을 구문 분석해야합니까 , 아니면이를 수행하는 명령이 있습니까?
다음 은 모든 추적 분기를 제공하는 명령입니다 ( 'pull'용으로 구성됨). 다음을 참조하십시오.
$ git branch -vv
main aaf02f0 [main/master: ahead 25] Some other commit
* master add0a03 [jdsumsion/master] Some commit
SHA와 긴 래핑 커밋 메시지를 살펴보아야하지만 입력이 빠르며 3 번째 열에 세로로 정렬 된 추적 분기가 표시됩니다.
분기 별 'pull'및 'push'구성에 대한 정보가 모두 필요한 경우에서 다른 답변을 참조하십시오 git remote show origin
.
최신 정보
자식 버전부터 1.8.5는 상류 지점을 표시 할 수 있습니다 git status
및git status -sb
두 가지 선택 :
% git rev-parse --abbrev-ref --symbolic-full-name @{u}
origin/mainline
또는
% git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"
origin/mainline
나는 git branch -av
당신이 어떤 브랜치를 가지고 있고 어떤 커밋에있는지만을 알려주고, 로컬 브랜치가 추적하고있는 원격 브랜치를 추론 할 수 있다고 생각 합니다.
git remote show origin
어떤 분기가 어떤 원격 분기를 추적하는지 명시 적으로 알려줍니다. 다음은 단일 커밋과라는 원격 분기가있는 저장소의 출력 예입니다 abranch
.
$ git branch -av
* abranch d875bf4 initial commit
master d875bf4 initial commit
remotes/origin/HEAD -> origin/master
remotes/origin/abranch d875bf4 initial commit
remotes/origin/master d875bf4 initial commit
대
$ git remote show origin
* remote origin
Fetch URL: /home/ageorge/tmp/d/../exrepo/
Push URL: /home/ageorge/tmp/d/../exrepo/
HEAD branch (remote HEAD is ambiguous, may be one of the following):
abranch
master
Remote branches:
abranch tracked
master tracked
Local branches configured for 'git pull':
abranch merges with remote abranch
master merges with remote master
Local refs configured for 'git push':
abranch pushes to abranch (up to date)
master pushes to master (up to date)
업데이트 : 글쎄요, 제가이 글을 올린 지 몇 년이 지났습니다! HEAD를 업스트림과 비교하는 구체적인 목적을 위해 이제 @{u}
업스트림 추적 분기의 HEAD를 참조하는 바로 가기 인을 사용 합니다. ( https://git-scm.com/docs/gitrevisions#gitrevisions-emltbranchnamegtupstreamemegemmasterupstreamememuem 참조 ).
Original answer: I've run across this problem as well. I often use multiple remotes in a single repository, and it's easy to forget which one your current branch is tracking against. And sometimes it's handy to know that, such as when you want to look at your local commits via git log remotename/branchname..HEAD
.
All this stuff is stored in git config variables, but you don't have to parse the git config output. If you invoke git config followed by the name of a variable, it will just print the value of that variable, no parsing required. With that in mind, here are some commands to get info about your current branch's tracking setup:
LOCAL_BRANCH=`git name-rev --name-only HEAD`
TRACKING_BRANCH=`git config branch.$LOCAL_BRANCH.merge`
TRACKING_REMOTE=`git config branch.$LOCAL_BRANCH.remote`
REMOTE_URL=`git config remote.$TRACKING_REMOTE.url`
In my case, since I'm only interested in finding out the name of my current remote, I do this:
git config branch.`git name-rev --name-only HEAD`.remote
The local branches and their remotes.
git branch -vv
All branches and tracking remotes.
git branch -a -vv
See where the local branches are explicitly configured for push and pull.
git remote show {remote_name}
This will show you the branch you are on:
$ git branch -vv
This will show only the current branch you are on:
$ git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
for example:
myremote/mybranch
You can find out the URL of the remote that is used by the current branch you are on with:
$ git remote get-url $(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)|cut -d/ -f1)
for example:
https://github.com/someone/somerepo.git
You can use git checkout
, i.e. "check out the current branch". This is a no-op with a side-effects to show the tracking information, if exists, for the current branch.
$ git checkout
Your branch is up-to-date with 'origin/master'.
I don't know if this counts as parsing the output of git config, but this will determine the URL of the remote that master is tracking:
$ git config remote.$(git config branch.master.remote).url
Yet another way
git status -b --porcelain
This will give you
## BRANCH(...REMOTE)
modified and untracked files
Another simple way is to use
cat .git/config
in a git repo
This will list details for local branches
Another method (thanks osse), if you just want to know whether or not it exists:
if git rev-parse @{u} > /dev/null 2>&1
then
printf "has an upstream\n"
else
printf "has no upstream\n"
fi
git branch -r -vv
will list all branches including remote.
Lists both local and remote branches:
$ git branch -ra
Output:
feature/feature1
feature/feature2
hotfix/hotfix1
* master
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/master
If you want to find the upstream for any branch (as opposed to just the one you are on), here is a slight modification to @cdunn2001's answer:
git rev-parse --abbrev-ref --symbolic-full-name YOUR_LOCAL_BRANCH_NAME@{upstream}
That will give you the remote branch name for the local branch named YOUR_LOCAL_BRANCH_NAME
.
I use this alias
git config --global alias.track '!sh -c "
if [ \$# -eq 2 ]
then
echo \"Setting tracking for branch \" \$1 \" -> \" \$2;
git branch --set-upstream \$1 \$2;
else
git for-each-ref --format=\"local: %(refname:short) <--sync--> remote: %(upstream:short)\" refs/heads && echo --URLs && git remote -v;
fi
" -'
then
git track
note that the script can also be used to setup tracking.
More great aliases at https://github.com/orefalo/bash-profiles
I use EasyGit (a.k.a. "eg") as a super lightweight wrapper on top of (or along side of) Git. EasyGit has an "info" subcommand that gives you all kinds of super useful information, including the current branches remote tracking branch. Here's an example (where the current branch name is "foo"):
pknotz@s883422: (foo) ~/workspace/bd $ eg info Total commits: 175 Local repository: .git Named remote repositories: (name -> location) origin -> git://sahp7577/home/pknotz/bd.git Current branch: foo Cryptographic checksum (sha1sum): bd248d1de7d759eb48e8b5ff3bfb3bb0eca4c5bf Default pull/push repository: origin Default pull/push options: branch.foo.remote = origin branch.foo.merge = refs/heads/aal_devel_1 Number of contributors: 3 Number of files: 28 Number of directories: 20 Biggest file size, in bytes: 32473 (pygooglechart-0.2.0/COPYING) Commits: 62
You can try this :
git remote show origin | grep "branch_name"
branch_name need to replaced with ur branch
If you are using Gradle,
def gitHash = new ByteArrayOutputStream()
project.exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = gitHash
}
def gitBranch = new ByteArrayOutputStream()
project.exec {
def gitCmd = "git symbolic-ref --short -q HEAD || git branch -rq --contains "+getGitHash()+" | sed -e '2,\$d' -e 's/\\(.*\\)\\/\\(.*\\)\$/\\2/' || echo 'master'"
commandLine "bash", "-c", "${gitCmd}"
standardOutput = gitBranch
}
Improving on this answer, I came up with these .gitconfig
aliases:
branch-name = "symbolic-ref --short HEAD"
branch-remote-fetch = !"branch=$(git branch-name) && git config branch.\"$branch\".remote || echo origin #"
branch-remote-push = !"branch=$(git branch-name) && git config branch.\"$branch\".pushRemote || git config remote.pushDefault || git branch-remote-fetch #"
branch-url-fetch = !"remote=$(git branch-remote-fetch) && git remote get-url \"$remote\" #" # cognizant of insteadOf
branch-url-push = !"remote=$(git branch-remote-push ) && git remote get-url --push \"$remote\" #" # cognizant of pushInsteadOf
Following command will remote origin current fork is referring to
git remote -v
For adding a remote path,
git remote add origin path_name
참고URL : https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking
'your programing' 카테고리의 다른 글
공용 저장소에서 이전 Git 커밋으로 롤백 (0) | 2020.09.29 |
---|---|
서비스 대 IntentService (0) | 2020.09.29 |
.net의 app.config 또는 web.config에서 설정 읽기 (0) | 2020.09.29 |
매크로에서 무의미한 do-while 및 if-else 문을 사용하는 이유는 무엇입니까? (0) | 2020.09.29 |
Windows 명령 줄에서 애플리케이션 종료 코드를 얻으려면 어떻게해야합니까? (0) | 2020.09.29 |