To checkout a branch with username in the URL so it prompts for credentials, you have several options:
## Method 1: Clone with Username and Checkout Branch
```bash
git clone -b branch-name https://username@wwwin-github.company.com/username/repository.git
```
Example:
```bash
git clone -b feature/new-feature https://john@wwwin-github.company.com/team/project.git
```
## Method 2: Clone First, Then Checkout Branch
```bash
# Clone with username (will prompt for credentials)
git clone https://username@wwwin-github.company.com/username/repository.git
# Then checkout the specific branch
cd repository
git checkout branch-name
```
## Method 3: If Repository Already Exists
If you already have the repository but need to update the remote URL:
```bash
# Update remote URL to include username
git remote set-url origin https://username@wwwin-github.company.com/username/repository.git
# Fetch and checkout branch (will prompt for credentials)
git fetch origin
git checkout branch-name
```
## Method 4: Using Full URL for Specific Branch
```bash
# One-liner to clone and checkout specific branch with username
git clone --branch branch-name https://username@wwwin-github.company.com/username/repository.git
```
## Method 5: For Existing Clone - Reset and Re-authenticate
If you're having credential issues with an existing clone:
```bash
# Reset credentials first
echo "url=https://wwwin-github.company.com" | git credential reject
# Update remote with username
git remote set-url origin https://username@wwwin-github.company.com/username/repository.git
# Now checkout branch (will prompt for credentials)
git checkout branch-name
git pull origin branch-name
```
## Step-by-Step Example:
```bash
# Step 1: Clone with username and specific branch
git clone -b development https://your-username@wwwin-github.company.com/team/project.git
# You'll be prompted:
# Password for 'https://your-username@wwwin-github.company.com':
# Step 2: Verify
cd project
git branch # Should show you're on 'development' branch
git log --oneline -5 # Should show recent commits
```
## If You Want to Switch Branches Later:
```bash
# This should prompt for credentials if not cached
git checkout another-branch
git pull origin another-branch
```
## For Personal Access Tokens:
If using GitHub personal access tokens:
```bash
git clone -b branch-name https://username:token@wwwin-github.company.com/username/repository.git
```
**Note:** Be careful with this method as it stores the token in git config.
## Verification:
After successful checkout:
```bash
git status
git branch --show-current # Shows current branch name
git log --oneline -3 # Shows recent commits
```
## Most Common Approach:
```bash
# This will prompt for credentials and checkout the branch directly
git clone -b your-branch-name https://your-username@wwwin-github.company.com/username/repository.git
```
The `-b` flag tells Git to checkout that specific branch immediately after cloning, and including the username in the URL ensures Git knows which credentials to request.