-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_my_first_remote_repo.txt
62 lines (52 loc) · 4.32 KB
/
create_my_first_remote_repo.txt
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
Earlier you learned how to initialize a new repo locally on your machine.
But what about the other scenario of cloning (downloading) a remote repository (online copy of a project) to your machine?
This gives a local copy of the repo on your machine that is ready for development, under version control, and tracked.
Once you have modified, staged, and committed any changes to files, you can then upload (push)to the remote repo.
##########################
# Cloning a remote repo #
#########################
On GitHub, go to a repository you want to clone and click the green 'code' button. Under the local tab, copy the HTTPS-URL or the SSH-URL
Open a terminal
cd to the folder into which you want to place the cloned repository
git clone [email protected]:gitusername/projectname.git # creates projectname folder via SSH
or https://github.com/gitusername/projectname.git # creates projectname folder via HTTPS (enter username/password as requested)
mv projectname/ projectname_repo # renamed so you know when editing that projectname is under GIT version control
cd projectname_repo # enter the repository folder
git status -v # view status of the repo
git remote show projectname # you can see the remote and local copies are the same
########################################
# Adding a remote for a new local repo #
########################################
git remote add origin [email protected]:GIT_USERNAME/REMOTENAME.git # e.g. git remote add origin [email protected]:BioinfGuru/My_money.git
git remote -v # To confirm remote created
#########################
# Push to a remote repo #
#########################
Important:
- It is likely that if this is a collaborative project, others will have pushed to the remote since you have cloned it.
- So you should first pull (or fetch/merge) from the repository again.
- All changes can then be merged and conflicts resolved before pushing back to the repository again.
- Otherwise, your push may be rejected.
- ORIGIN/MASTER is just the default remotename/branchname given by 'git init' (don't change them, everyone understands them)
git pull remotename branchname # or use fetch/merge (see below)
git push remotename branchname # if no conflicts
###########################
# Other relevent commands #
###########################
git remote -v # view your remotes and their URLs
git remote show remotename # display metadata of remotename
git remote add remotename <ssh> # using ssh key, adds a remote (to local list of remotes)
git remote add remotename <url> # using https, adds a remote (to local list of remotes)
git remote remove remotename # delete a remote (from local list of remotes)
git branch -u remotename/branchname # current branch to track remote/branch (use --unset-upstream to undo
git branch --unset-upstream remotename/branchname # undo above
git switch -c branchname --track remotename/branchname # creates + switches to local branchname that tracks remotename/branchname
git fetch remotename # gets metadata of remotename, updates tracking branches
git fetch --all # gets metadata of all tracked remotes, updates tracking branches
git pull remotename branchname # pulls + merges from remote (better to use fetch/merge)
git push remotename branchname # pushes checkedout branch to remote/branch (or creates remote/branch if none exists)
# Renaming (not tested these commands - don't like the idea - may screw with history)
WARNING: NEVER change the name of the MASTER/MAIN/DEFAULT branch --> will definetly screw with collaborators history
git remote rename <old> <new> # renames a remote repo - easier on github
git push -u remotename <newbranchname> # push <newbranchname> to remotename (-u sets up tracking)
git push remotename --delete branchname # delete branchname from remote (recoverable for a short time)