Check out a remote branch in git
If you would like to checkout the branch groups
, you can simply say this in recent versions of Git:
git fetch origin
git checkout groups
This will automatically track origin/groups
from a local branch groups
.
In older Git versions you need to say this:
git fetch origin
git checkout --track origin/groups
Related cards:
Git: How to check out branches that exist on multiple remotes
So you're using multiple remotes that offer the same branch?
$ git branch -a | grep my-branch
remotes/something/my-branch
remotes/origin/my-branch
And when trying to check out that remote branch, it fails for you with an error li...
Git: Delete a branch (local or remote)
To delete a local branch
git branch -d the_local_branch
To remove a remote branch (if you know what you are doing!)
git push origin :the_remote_branch
or simply use the new syntax (v1.7.0)
git push origin --delete the_remote_b...
How to mirror a git repo to a new remote
Say you want to move a git repository from one remote (perhaps Github) to another (perhaps Gitlab).
If you have the repo checked out, you still should make sure to mirror all branches of the old remote, not only those you happen to have checked o...
Git: List remote branches
Sometimes you may need to figure out what branches exist on a remote repository so you can pull them down and check them out, merge them into your local branches, etc. You can see the remote branches by saying
git branch -r
Or, if you wa...
Git: Retrieve a file from a different branch or commit
To access files from another branch or past commit without doing a complete checkout, you can either use
git show branch:file
git show commit:file
to display, or check out the file into your working directory with
git checkout bra...
git "fatal: bad config file line" after checking out branch
If git gives you an error message such as "fatal: bad config file line 123 in .git/config" after you tried to checkout a branch with a very long branch name, you very likely come across a bug in git version < 1.8.
You should ask someone with a ne...
Git: Push a new branch and track it immediately
When you create a new branch and push it to origin
, you won't be tracking it. This means a git pull
won't know its remote version.
You could use difficult commands to set up a branch's tracking but it's easier to just push it like this:
...
How to find out what is running on a port on a remote machine
By convention, common protocols use a defined port, like 80 for HTTP or 443 for HTTPS.
You can use nmap
to find out what service is running behind a given port, and most often see some details about it. This can be helpful if servers don't offe...
Git: Merge a single commit from another branch
This is called "cherry-picking".
git cherry-pick commit-sha1
Note that since branches are nothing but commit pointers, cherry-picking the latest commit of a branch is as simple as
git cherry-pick my-feature-branch
**Be aware that c...