Download presentation
Presentation is loading. Please wait.
Published byAdrian Hancock Modified over 8 years ago
1
Lecture 5 Remotes Sign in on the attendance sheet! Turn in homework at the front!
2
Today Fetching Pushing Github
3
Scenario: Alice, Bob, and Charlie collaborate on a project, but each on their own computer b4e2c29: initial commit AliceBobCharlie 8fc42c6: heapchecker no longer infloops
4
Scenario: Alice, Bob, and Charlie collaborate on a project, but each on their own computer b4e2c29: initial commit AliceBobCharlie 8fc42c6: heapchecker no longer infloops 6f96cf3: don’t create headers in free blocks 8fc42c6: heapchecker no longer infloops
5
Scenario: Alice, Bob, and Charlie collaborate on a project, but each on their own computer b4e2c29: initial commit AliceBobCharlie 8fc42c6: heapchecker no longer infloops 6f96cf3: don’t create headers in free blocks 8fc42c6: heapchecker no longer infloops How does Alice get commit 6f96cf3 to Bob and Charlie?
6
Scenario: Alice, Bob, and Charlie collaborate on a project, but each on their own computer b4e2c29: initial commit AliceBobCharlie 8fc42c6: heapchecker no longer infloops 6f96cf3: don’t create headers in free blocks 8fc42c6: heapchecker no longer infloops How does Alice get commit 6f96cf3 to Bob and Charlie? Idea 1: Bob and Charlie each fetch the commit from Alice. Idea 2: Alice pushes the commit to Bob and Charlie.
7
Fetching (both Bob and Charlie must do this) Two steps: 1.Tell git to treat Alice’s repository as a “remote repository” or a “remote” and tell git where to find it. This needs to happen only once. 2.Tell git to fetch the commits from the remote repository. Note: if you used `git clone` to get your repository, the url that you cloned from was automatically set as a remote repository.
8
git remote add Example use: git remote add origin andrew@128.237.11.111:/home/andrew/linuxandrew@128.237.11.111:/home/andrew/linux (not my actual IP address) Adds a remote repository called “origin” located at andrew@128.237.11.111:/home/andrew/linux (through SSH) andrew@128.237.11.111:/home/andrew/linux “origin” is the default name for a remote, since often times the first remote you have is the one you clone from
9
git remote Example use: git remote Lists the names of all your remotes, i.e. origin afs alice
10
git remote -v Example use: git remote -v Verbosely lists the names of all your remotes, i.e. origin andrew@128.237.11.111:/home/andrew/linuxandrew@128.237.11.111:/home/andrew/linux afs adbenson@unix.andrew.cmu.edu:/afs/andrew.cmu.edu/course/15/150/handoutadbenson@unix.andrew.cmu.edu:/afs/andrew.cmu.edu/course/15/150/handout alice alice@alicePC:~/private/secretproject.gitalice@alicePC:~/private/secretproject.git github https://github.com/torvalds/linux.git
11
Git Remote URLs 4 choices: HTTPS, SSH, local, git HTTPS: git objects and commits are transferred over web protocols. Pretty easy to set up, unless you need authentication. SSH: git objects and commits are transferred over the SSH protocol. Requires a ssh daemon to be running, allows authentication.
12
git fetch Example use: git fetch origin Downloads and updates all branches published by the remote. Stores these branches as /. For example, if origin has an updated master branch, then running `git fetch origin` will update your local branch called “origin/master”. These branches like origin/master are called “remote-tracking branches”, because their states should match the origin’s branches’ states. Does NOT affect your own branches, like master!
13
Example use: git branch -r git branch -a Git branch -r lists all remote-tracking branches. Git branch -a lists all branches, whether local or remote-tracking. git branch -r or git branch -a
14
How do you actually bring in the remote changes?
15
How do you actually *merge* in the remote changes?
16
git merge origin/master
17
git pull Example use: git pull origin Runs `git fetch `, then `git merge / `. Ex) runs `git fetch origin`, then `git merge origin/master`.
18
Sometimes pulling is inconvenient In order for people to pull from you, you have to be running a web server or a SSH daemon or something requiring setup, usually. If you’re not collaborating with other people, no one else has your changes and your version control isn’t very distributed.
19
Pushing is hard too If everyone was allowed to push to you, then people could push random commits to troll you. Even if you kept a whitelist of everyone that was allowed to push to you, it’s rather inconvenient for everything in your working directory to get wiped every time someone pushes. -> With git, you’re not allowed to push to a normal repository. This requires a “bare repository”.
20
Bare Repositories Created with `git init --bare` Has no working directory, just the contents of what the.git folder would have had Is meant to only be pushed to Fortunately, you rarely have to deal with doing this since Github does all of this behind the scenes for you
21
Using Github as a remote
22
git push Example use: git push origin master Updates the remote-tracking branch ( / ) and uploads the necessary commits for that branch to origin You must be fully up-to-date with the remote in order to push! Otherwise your push will be rejected.
23
What happens if you run `git push`? A. git exception B. git pushes current branch to origin (default remote) C. git pushes all branches to origin (default remote) D. git pushes current branch to all remotes E. git pushes all branches to all remotes F. git pushes to a random remote G. segfault
24
What happens if you run `git push`? A. git exception B. git pushes current branch to origin (default remote) git2.0 default C. git pushes all branches to origin (default remote) pre-git2.0 default D. git pushes current branch to all remotes E. git pushes all branches to all remotes F. git pushes to a random remote G. segfault
25
Summary Configuring remotes: git remote [-v] – lists remotes [verbosely] git remote add - configure a new remote git branch –r – lists remote-tracking branches Fetching: git fetch - downloads updates to all remote-tracking branches to match the remote git pull - runs `git fetch`, then merges in updates to the current branch Pushing: git push - uploads changes in your branches to the remote
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.