Forem

fiona
fiona

Posted on • Edited on

2 2

Git: push to a new remote branch

It is important to specify <remote> <branch> in every pull and push in the scenario. If not specified, would be default master.

  • branch
# list all branches, including local and remote
git branch -a

# create new local branch
git branch <new_branch_name>

# switch to another branch
git checkout <another_branch>

# switch no to new local branch (combine the steps above)
git checkout -b <new_branch_name>

# delete a branch, use -D for force delete
# need to checkout to another branch before delete
git branch -d <branch>
Enter fullscreen mode Exit fullscreen mode
  • clone
# clone a repository in specific remote branch
git clone --branch <branch_name> <remote_repo_url>
git clone -b <branch_name> <remote_repo_url>

# clone a specific remote branch 
# and does not track other remote branch
git clone -b <branch_name> --single-branch <remote_repo_url>
Enter fullscreen mode Exit fullscreen mode
  • pull (fetch+merge)
git pull origin <branch>
Enter fullscreen mode Exit fullscreen mode
  • push
# push to a new remote branch not yet created
git push --set-upstream <remote> <branch_name>
git push -u <remote> <branch_name>

# push to remote branch
git push <remote> <branch_name>

# delete a remote branch
git push <remote> --delete <remote_branch_name>
Enter fullscreen mode Exit fullscreen mode

Usually <remote> would be origin unless working with another repository (eg. deploying app to heroku)
origin stands for the remote repository that a project was originally cloned from.


  • overwrite local repository
git fetch --all
git reset --hard origin/master
Enter fullscreen mode Exit fullscreen mode

replace master with whatever branch originally wanted

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more