-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremotes.notes
More file actions
114 lines (87 loc) · 3.79 KB
/
Copy pathremotes.notes
File metadata and controls
114 lines (87 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
* // ---------- REMOTES ---------- // *
// Local Git repositories do not require a network connection
// Remote repositories ("remotes") are hosted by servers over a network
// Remotes allow easy collaboration
// Push local repository changes to the remote
// Fetch remote changes to the local repository
// Git is designed to be a distributed version control
// All repositories are the same
// Often, one remote is designated as the primary repository for collaboration
# Add a remote w/ URL
git remote add origin <URL of the repo> // Convention is to call the primary main remote "origin"
// On the repo page in GitHub, press "Clone or download" and copy the HTTP URL
# List all remotes
git remote
git remote -v // More information on your remotes (URL etc.)
# Show remote branches
git branch -r
# Show all branches
git branch -a
* // ---------- REMOTE BRANCH ---------- // *
# Set remote using HTTPS
git remote set-url https://github.com/USERNAME/REPO.git
# Set remote using SSH
git remote set-url git@github.com/USERNAME/REPO.git
# Change the remote URL/URI
git remote set-url <remote name> <new git url>
// e.g. git remote set-url origin git@github.com/USERNAME/REPO.git
* // ---------- PUSH ---------- // *
// Push local commits to the remote server
# Push a local branch to a remote that is not being tracked yet
git push -u <remote name> <branch to push> // The -u option means to track the branch
// Use -u every time we are pushing a new branch, so that the remote branch is then tracked
# Push an a branch to a remote
git push <remote name> <branch to push> //
# Push the current branch to the tracked remote
git push
# Push all branches to the remote
git push <remote name> --all
// The remote can be viewed in the .git\config file
* // ---------- FETCH ---------- // *
// Pull commits from the remote server to the local machine
# Clone a remote repository
git clone <URL> // If no name is specified, it will use the git repository to create a directory
git clone <URL> <name of directory to clone to>
# Snchronise with the remote repository and pull all data
git fetch
OR:
git fetch <name of remote>
// Performing a fetch will not affect the current branch
// It purely check in with the server to see if there are any changes
Best practice:
- Fetch before you work
- Fetch before you push
- Fetch before you go offline
- Fetch often
* // ---------- FETCH + MERGE ---------- // *
# Perform a git fetch and git merge in one command
git pull
* // ---------- TRACKING / NON-TRACKING ---------- // *
// If the remote branch is not tracked, then it needs to be specified each time you push/pull
// If it is, then the remote branch does not need to be specified
// If the -u option was not specified when creating the remote
// Or, if we want to track a new remote branch
# Track a remote branch
git branch -u <upstream> <branch name>
// upstream e.g. = origin/non_tracking
# Untrack a branch
git branch --unset-upstream <branch name>
Note:
// origin/master is the tracking branch for the remote branch (it is not the actual remote branch)
// It is a tracking branch that is on the local machine
* // ---------- REMOTE BRANCH CHECKOUT ---------- // *
// You cannot checkout remote branches
// Instead, you need to create a new branch from the remote branch
# Creating a branch from a remote branch
git branch <name of the new branch> <untracked remote branch>
* // ---------- DELETE REMOTE ---------- // *
# To delete a remote
git remote rm <name of remote>
* // ---------- DELETE A REMOTE BRANCH ---------- // *
// Remove a branch from the remote repository
// Useful when a feature branch is complete and merged
# Delete a remote branch
git push <remote name> :<name of remote branch to delete> // Old school method
// e.g. git push origin :origin/new_feature
OR:
git push <remote name> --delete <name of remote branch to delete>