Git: doing common tasks (part 2)
In this part we will focus interacting with remote repositories, remote repositories are used when people want to collaborate.
In this part we will focus interacting with remote repositories, remote repositories are used when people want to collaborate.
How to view a repository fetch and push urls
The first url is used to fetch data for the remote repository and the second one to push data to the remote repository.
Note: by default the naming of a remote repository is origin.$ git remote -v
origin https://github.com/kpatronas/rdp_over_ssh_proxy.git (fetch)
origin https://github.com/kpatronas/rdp_over_ssh_proxy.git (push)
How to view info about the remote repository
It will also show all remote branches$ git remote show origin
* remote origin
Fetch URL: https://github.com/kpatronas/rdp_over_ssh_proxy.git
Push URL: https://github.com/kpatronas/rdp_over_ssh_proxy.git
HEAD branch: main
Remote branch:
main tracked
Local branch configured for 'git pull':
main merges with remote main
Local ref configured for 'git push':
main pushes to main (fast-forwardable)
How to view the remote branches$ git branch -r
origin/HEAD -> origin/main
origin/main
How to view if local / remote branches are up to date$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)nothing to commit, working tree clean
How to get an update of the differences between local and remote repository
git fetch can get an update from the remote repository about the commits that have been made to.$ git fetch
Then running git log we can identify if the HEAD points to the same commit in local and remote repository or not. In the bellow case the local repository is ahead by one commit vs the remote origin repository.$ git log
commit d22898352e2da3683beadf66cb3f57c382abb6c2 (HEAD -> main)
Author: Konstantinos Patronas <kpatronas@gmail.com>
Date: Mon Jun 27 14:57:11 2022 +0300add a dotcommit 74f49805e2e7232ac6663dca0d36b09437c7fd56 (origin/main, origin/HEAD)
Author: Konstantinos Patronas <kpatronas@gmail.com>
Date: Wed Sep 15 16:05:50 2021 +0300Update rdp.ps1
How to merge changes after git fetch$ git merge origin/main
How to fetch and merge in a single command
git pull == git fetch + git merge origin/master$ git pull
How to switch to another remote branch
This command updates all files in the working tree with the files of the remote repository branch.$ git checkout new_feature
How to push a local branch to a remote repository
Assume you have created a local branch and you want to push it to the remote repository.$ git push -u origin <branch_name>