Git and Github Tutorial - Remote Repository - Part 12

Hi, Today in iThePro we will learn how to use Git and how to use with Github to build software and develop it. In this part we will see how to work with remotes repository.

Using local and remote repository:
Push: The process when we take our commits and put them on the remote server, so other people can see them.

Fetch: The process when we pull over changes down from remote server to local machine, so it come into our origin master branch.

Origin/Master: is just branch try to stay sync with the remote server.

Adding a remote repository:
git remote
This will give us a list of all remotes git know about them.
git remote add <alias> <url>
 This will create a new remote origin (alias) that point to the remote URL.
git remote -v
This will give us more information about the URL git is going to use for both of fetching and pushing.
git remote rm <alias>
This will remove the remote repository .

Creating a remote branch:
git push -u <alias> master
 This will push the master branch to the remote repository <alias> + start tracking the master branch with <alias>.
git branch -a
This will give us all branch include remotes.

Cloning a remote branch:
git clone <URL>
 This will download the the git file and save it on the local machine, so you can start working on it.

Tracking Remote Branch:
As we see before we push our project to github and we make the <alias> branch to track change and stay sync with it.

Pushing changes to a remote repository:
Once we're made changes, Now it's time to pull those changes to the remote repository.
git pull <alias> master
Fetching changes from a remote repository:
git fetch <alias>
This will fetch what in the remote repository and sync the local repository with it.
git log --oneline -2 <alias>/<branch-name>
 Now you can see the new commits coming from the remote repository.

Merging in fetched changes:
git merge <alias>/master
This will merge the <alias> into our master branch, so we will keep up-to-date with the remote repository.

==> git pull = git fetch + git merge
Checking Out remote branches:
git branch <branch-name> <alias>/<branch-name>
This  will create a local branch points to the remote branch.
git checkout -b <branch-name> <alias>/<branch-name>
This will create and checkout to the new branch.

Pushing to an updated remote branch:
Always fetch then merge and finally push.

Deleting a remote branch:
git push <alias> :<branch-to-delete>
 This will remove the remote branch.

git push origin --delete <branch-to-delete>
See the Git and Github Tutorials.



Oussama Amri 21 years, security professional from Tunisia. Lover of computer science especially programming and secuirty. Follow me On :

Popular Posts Powered by Blogger.