Useful commands
Clone a repository
For the first time
When you clone a repository, Git automatically adds a shortcut called origin that points back to the “parent” repository. Just run:
Problems
When I run the clone command with the ssh, I have the following error:
If you encounters problems with the ssh, do not directly go to the https ! Try adding your ssh key to your ssh agent by running:
For more information check out this link.
The historic of the project is waaaaaay too big that the cloning it takes forever. Plus it might fill my drive !
I you feel that you don't need the full history right now, you can use the --depth <depth>
option in order to truncated the history. It will create a shallow clone with the history truncated to the specified number of commits.
More can be found here
For a second time
You can achieve that by running the following command :
The command use the --dissociate
option. With this option, the new repository made will use the repository specify with the --reference
option, to borrow objets from it, in order to reduce network transfer. Once the clone operation is done, the two repositories remain independent ! Either one can be deleted without impacting the other !
You can also us the --reference
option without the --dissociate
one. But keep in mind that it will create dependencies between the two repositories. see NOTE for the --shared
option in this link.
Create a branch
Pulling work made on the remote
If we want to explicitly create a merge commit when pulling :
git pull --no-ff
If you don't want to create a merge commit no matters what :
git pull --ff-only
Note: It's a good practice to use the option --ff-only
without thinking and then decide if we want to merge or rebase if an error shows up.
Rebase (instead of merge commit)
git pull --rebase origin master
Explanation(s): Rebasing allow to keep a cleaner history for a repository.
Warning: Use
rebase
only if the changes do not deserve a separate branch.
git rebase --abort
Explanation(s): Cancel a current rebase.
Merge branches (instead of rebasing)
git merge origin/develop
Checkout a branch
Commiting (and pushing)
Checking the graph of the repository
Acknowledgements
Ce(tte) œuvre est mise à disposition selon les termes de la Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.
Last updated
Was this helpful?