git checkout 'another_branch'
Or
git checkout origin 'another_branch'
Or
git checkout origin/'another_branch'
This question is related to
git
github
version-control
gitlab
git-checkout
Check remote branch list:
git branch -a
Switch to another Branch:
git checkout -b <local branch name> <Remote branch name>
Example: git checkout -b Dev_8.4 remotes/gerrit/Dev_8.4
Check local Branch list:
git branch
Update everything:
git pull
[git checkout "branch_name"
]
is another way to say:
[git checkout -b branch_name origin/branch_name
]
in case "branch_name" exists only remotely.
[git checkout -b branch_name origin/branch_name
] is useful in case you have multiple remotes.
Regarding [git checkout origin 'another_branch'
] I'm not sure this is possible, AFAK you can do this using "fetch" command
-- [git fetch origin 'another_branch'
]
With Git 2.23 onwards, one can use git switch <branch name>
to switch branches.
Check : git branch -a
If you are getting only one branch. Then do below steps.
git config --list
git config --unset remote.origin.fetch
git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
I am using this to switch one branch to another anyone you can use it works for me like charm.
git switch [branchName] OR git checkout [branchName]
ex: git switch develop OR
git checkout develop
If you want the branch to track the remote branch, which is very important if you're going to commit changes to the branch and pull changes etc, you need to add a -t
for the actual checkout like so:
git checkout -t branchname
Useful commands to work in daily life:
git checkout -b "branchname" -> creates new branch
git branch -> lists all branches
git checkout "branchname" -> switches to your branch
git push origin "branchname" -> Pushes to your branch
git add */filename -> Stages *(All files) or by given file name
git commit -m "commit message" -> Commits staged files
git push -> Pushes to your current branch
If you want to merge to dev from feature branch, First check out dev branch with command "git branch dev/develop" Then enter merge commadn "git merge featurebranchname"
The Best Command for changing branch
git branch -M YOUR_BRANCH
Switching to another branch in git. Straightforward answer,
git-checkout - Switch branches or restore working tree files
git fetch origin <----this will fetch the branch
git checkout branch_name <--- Switching the branch
Before switching the branch make sure you don't have any modified files, in that case, you can commit the changes or you can stash it.
What worked for me is the following:
Switch to the needed branch:
git checkout -b BranchName
And then I pulled the "master" by:
git pull origin master
Source: Stackoverflow.com