This guide shows you how to use Git to manage a remote repository.
Prerequisites
-
You have configured an SSH key or an HTTPS password.
Step 1: Get repository information
-
Log in to Codeup and click a repository from the repository list.
-
On the Source page of the target repository, click Clone/Download, and then copy the SSH or HTTPS URL.
To clone the repository, copy its SSH or HTTPS URL. Most users prefer SSH because it enables secure, password-free login and offers better performance.
Step 2: Use the CLI
The following steps show how to create a local README.md file and push it to the remote repository.
-
Open Git Bash or a shell terminal on your computer. Run the following command to clone the repository.
git clone <repository-url>If you use SSH, make sure that you have configured your SSH public key. If you use HTTPS, enter your username and password.
-
Change to the repository directory.
cd <repo-name> -
Create a README.md file.
vi README.md -
Add the file to the index.
git add README.md -
Create a commit.
git commit -s -m "Initial commit" -
Push the commit to the remote branch.
git push origin master
Common Git commands
-
Switch to the master branch.
git checkout master -
View the local repository's remote URL.
git remote -v -
Set a local branch to track a remote branch, such as the remote master branch.
git branch -u origin/master -
Synchronize your local branch with its remote counterpart. This command fetches remote changes and merges them into your local branch.
git pull -
Synchronize with the remote branch using rebase. This command reapplies your local commits on top of the latest remote changes.
git pull --rebase -
Create a new branch and switch to it.
git checkout -b <branch> <start-point> -
View the status of your working directory and staging area.
This command displays the state of the working directory and the staging area, listing which files are modified, staged, or untracked.
git status
References
-
For more information, see Pro Git.
-
For a video tutorial, see The Complete Guide to Git.