To initialize a local repo from a remote repo we need to clone the remote repo.
git clone https://github.com/josejuanWSB/test_repo.git master
To initialize a remote repo in GitHub from a local repo we need to:
- Create the repo in GitHub
- Initialize local repo
git init
It makes all the changes in the local repo be in the remote repo in GitHub
-
Stage all the files:
git add .
"." is a key for all the files in the directory
-
Reflect the changes in the local repository (.git directory)
git commit -m "First Commit"
-
Push the changes to the remote repository
git push https://github.com/josejuanWSB/test_repo.git master
It synchronizes the remote repo in GitHub to the local repo, making available the last changes made in the remote repo to the local repo.
To try it you can change something in the remote repo by the GitHub editor (right corner inside a file) or someone of your team can make changes and then you can make a pull.
git pull https://github.com/josejuanWSB/test_repo.git master
When two developers introduce changes in the same line of code this can generate problems.
To reproduce this scenario you can:
I. Change a line in the remote repo and make a commit by GitHub editor, like before.
II. Change the same line in the local repo by adding something different than in the remote repo
III. Try to pull:
git pull https://github.com/josejuanWSB/test_repo.git master
IV. If it fails, then:
- First you need to add and reflect the changes
- Then:
git add . git commit -m "Committing on local repo" git pull https://github.com/josejuanWSB/test_repo.git master
If meanwhile pulling it prompts the vi/unix command line editor, don't panic and press -> :wq (save and exit)
V. There is a conflict, that needs to be solved manually.
- Go to the file and delete the comments by git, and the code that you don't want
- Then:
git add . git commit -m "Conflict resolved" git push https://github.com/josejuanWSB/test_repo.git master
- If now you try to git pull, it will display: "Already up to date"