Learning Git Part 2 Flashcards
Starting at Ch7
What is the command:
git push
Upload data to a remote repository.
A remote repository is the repository that is not a local repository (on your computer). A remote repository is like the Github server.
Starting from your local repository, how do you turn that into a remote repository?
Follow these steps:
1. Create a local repository using
git init. You also need to make at least 1 commit.
2. Create a remote repository on a hosting service (Github)
3. You may upload data from the local repository to the remote repository
Starting from a remote repository, how do you work on a Git project?
Follow these steps:
1. Find or create a remote repository
2. Clone (copy) the remote repository to your computer, which will create a local repository
3. Work with local and remote repositories by uploading data back to remote repository.
Why do we use remote repositories?
- Easily back up your project somewhere other than your computer
- Access a Git project from multiple computers
- Collaborate with others on Git projects
What are the steps to create a remote repository and upload some data to it?
- Create the repository on the hosting service
- Add a connection to the remote repository in the local repository
- Upload (or push) data from the local repository to the remote repository
How do you add a connection to the remote repository?
A local repository can communicate w/a remote repository when the local repository has a connection to the remote repository stored within it. This connection will have a name, which we will call remote repository shortname or just shortname.
You must explicitly link the URL of the Github repository to the shortname value you selected by using this command:
~~~
git remote add <shortname> <URL>
~~~
Add a connection to a remote repository named *shortname* at *URL*</URL></shortname>
Once a connection to a remote repository is stored in a local repository, you are able to connect to the remote repository by referring to the shortname rather than the URL in the command line.
What happens when you clone a remote repository to create a local repository?
Git automatically adds a connection to the remote repository with the default shortname
origin.
There is nothing special about the name “origin”, it’s just convention.
Explain the following commands:
git remote
```
git remote -v
~~~
git remote: List the remote repository connections stored in the local repository by shortname
git remote -v: List the remote repository connections in the local repository with shortnames and URLs.
What is a remote branch?
When you push a local branch to a remote repository, you will create a remote branch. A remote branch is a branch in a remote repository.
Do remote branches automatically update when you make more commits on local branches?
No. You have to explicitly push commits from a local branch to a remote branch. Every remote branch (that a local repository knows about) also has a remote-tracking branch. This is a reference in a local repository to the commit a remote branch pointed at the last time any network communication happned with the remote repository. You can think of it as being like a bookmark.
What is an upstream branch?
You can set up a tracking relationship between a local branch and a remote branch by defining which remote branch a local branch should track. This is referred to as the upstream branch.
There are some cases where Git will set the upstream branch automatically, but in other cases you have to set it explicitly.
What does Git need to know when you push work from a local branch to a remote branch?
When you push work from a local branch to a remote branch, Git needs to know which remote branch you want to push to. If the local branch has an upstream branch defined for it, you can use
git pushwith no arguments, and Git will automatically push the work to that branch.
However, if no upstream branch is defined for the local branch you’re working on, you’ll need to specify which remote branch to push to when you enter the
git pushcommand (if you don’t, you get an error message).
What is the following command
git push <shortname> <branch_name>
Upload content from branch_name to the shortname remote repository
After you execute the
git pushcommand, two things will happen:
1. A remote branch will be created in the remote repository
2. A remote-tracking branch will be created in your local repository
What is the following command:
girt branch --all
List local branches and remote-tracking branches